Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

How to refresh content tree on page publish

Vote:
 

Using EPiServer CMS 11
Using EPiServer Find 13

I've created an initialisation module that moves pages 'on publish', which could include creating other pages and adding children. My issue is that if I create content 'on publish', then many times the new content is not displayed in the content tree until I reload page. Our concern is this isn't a very good experience for editors.

I've tried hooking into the dojo 'topic's to check which event is published, but I cant find any specific publish event. Next issue is I dont know how to refresh only a single panel, so I presume I have to reload the entire page? 

aspect.after(topic, 'publish', function (topicName,event) {
    topic.publishMap = topic.publishMap || {};

    if (!topic.publishMap[topicName]) {

        if (window.printevents) {
            console.log(JSON.stringify(topicName));
            console.log(JSON.stringify(event));
        }
    }
}, true);

the above javascript is for listening to every single event that is published, but nothing matches precisly and succintly 'on publish'

any suggestions?

#197830
Oct 15, 2018 12:59
Vote:
 

Hi Noel

You could try and take some inspiration from Tahir's "Reload children" add-in: https://world.episerver.com/blogs/Tahir-Naveed/Dates/2016/11/adding-a-menu-item-into-context-menu---episerver-10-1-way/

David

#197865
Oct 15, 2018 23:28
Vote:
 

There is no built-in way to update page tree, but there is a hack that can help you. It updates the whole tree, not just the children.

I also have initialization module. I change prototype of Publish method and prototype of MainNavigationComponent:

define([
    "dojo/_base/declare",
    "dojo/on",
    "dojo/topic",
    "dojo/when",
    "epi/_Module",
    "epi-cms/contentediting/command/Publish",
    "epi-cms/component/MainNavigationComponent"
], function (
    declare,
    on,
    topic,
    when,
    module,
    Publish,
    MainNavigationComponent
) {

    return declare([module], {

        initialize: function () {
            this.inherited(arguments);

            var originalExecute = Publish.prototype._execute;
            Publish.prototype._execute = function () {
                var result = originalExecute.apply(this, arguments);
                when(result).then(function () {
                    topic.publish("custom-tree-reload");
                });
                return result;
            }

            var originalPostCreate = MainNavigationComponent.prototype.postCreate;
            MainNavigationComponent.prototype.postCreate = function () {
                originalPostCreate.apply(this, arguments);

                this.own(topic.subscribe("custom-tree-reload", function () {
                    var showAllLanguages = this.tree.get("showAllLanguages");
                    // set the same value, just want to trigger refresh
                    this.tree.set("showAllLanguages", showAllLanguages);
                }.bind(this)));
            }
        }
    });
});

I also have sample implementation publish event:

using System.Web.Mvc;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
using AlloyTemplates.Business.Rendering;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAccess;
using EPiServer.Security;
using EPiServer.Web;

namespace AlloyTemplates.Business.Initialization
{
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class CustomizedRenderingInitialization : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            //Add custom view engine allowing partials to be placed in additional locations
            //Note that we add it first in the list to optimize view resolving when using DisplayFor/PropertyFor
            ViewEngines.Engines.Insert(0, new SiteViewEngine());

            context.Locate.TemplateResolver()
                .TemplateResolved += TemplateCoordinator.OnTemplateResolved;


            ServiceLocator.Current.GetInstance<IContentEvents>().PublishedContent += CustomizedRenderingInitialization_PublishedContent;
        }

        private void CustomizedRenderingInitialization_PublishedContent(object sender, EPiServer.ContentEventArgs e)
        {
            if (e.ContentLink.ID == 9) // prevent from circular call for Alloy Meet
            {
                return;
            }

            var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();

            var pageData = contentRepository.Get<PageData>(new ContentReference(9));
            pageData = pageData.CreateWritableClone();
            pageData.Name = pageData.Name + "!";
            contentRepository.Save(pageData, SaveAction.Publish);
        }

        public void Uninitialize(InitializationEngine context)
        {
            ServiceLocator.Current.GetInstance<TemplateResolver>()
                .TemplateResolved -= TemplateCoordinator.OnTemplateResolved;
        }

        public void Preload(string[] parameters)
        {
        }
    }
}

The tree is updated.

#198013
Oct 18, 2018 21:31
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.