1

I have a carousel component in our website. We are creating items for each carousel under a particular folder item. I am using this folder item as data source for the rendering component. We changed the carousel and try to publish the page item in experience editor with related items.

This is publishing the parent folder item and not the children items of the folder items.

I read it in an article that Sitecore only publishes the items which are directly related to published items.

Is there any way to publish the child items of the datasource item.

1
  • Can you provide more information here? Based on what I've understood, you want to publish other items found in another container. Those should get published if some items need are published by content authors Mar 21, 2019 at 11:14

2 Answers 2

1

What you could try is to create new event handler for publish:itemProcessed event and check if the item which was published is the datasource folder. If the answer is yes, publish all the child items:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <events>
      <event name="publish:itemProcessed">
        <handler type="Your.Assembly.Namespace.ClassName, Your.Assembly" method="PublishDatasourceChildren" />
      </event>
    </events>
  </sitecore>
</configuration>

and code:

public void PublishDatasourceChildren(object sender, EventArgs args)
{
    var itemUri = ((Sitecore.Publishing.Pipelines.PublishItem.ItemProcessedEventArgs)args).Context.ItemUri;
    var item = Database.GetItem(itemUri);

    if (item != null /*&& extra checks here*/)
    {
        var targetDatabase = Database.GetDatabase("web"); // maybe you need to change this one?

        foreach (Item child in item.Children)
        {
            var publishOptions = new PublishOptions(item.Database, targetDatabase, PublishMode.SingleItem, item.Language, DateTime.Now);
            var publisher = new Publisher(publishOptions);
            publisher.Options.RootItem = child;
            publisher.Options.Deep = false;
            publisher.Publish();
        }
    }
}
2
  • Thanks Marek. Its not working ,datasource child items are skipped while publishing
    – Manikanta
    Mar 22, 2019 at 12:16
  • If you configure this handler, it will be executed for the parent datasource folder. Add code which will check if this item is datasource in /*&& extra checks here*/ place and it will publish your child items
    – Marek Musielak
    Mar 22, 2019 at 13:49
2

This is a common problem with datasources that rely on child items of the datasource.

The best way I have found to resolve this, is by either running an Incremental publish on the site, or changing the workflow to run scheduled publishes.

Incremental Publish

If your content editors need to run ad-hock publishes, an incremental publish will catch everything in the publish queue. That is everything that has been edited since the last publish was run. So even tho the child items might not be picked up by the related items, because a content editor has changed them, they would be in the publish queue and this will pick them up.

The downside is that, ad-hoc publishes clear the entire html cache every time. So this might not be the best option if you have a lot of edits happening all the time.

Scheduled Publish

A better option might be to use something like SiteCron to schedule site wide incremental or smart publishes at specific times. Say, every hour or twice a day. That might lessen the amount of cache clears that happen on the site.

Of course, if you don't do that many edits, ad-hoc publishes might be fine. But make sure you do an incremental publish of the site, and not a related publish of the item so that it catches all the datasource item children.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.