2

I have a requirement to publish all the dynamic components associated with the page.Also, the dynamic components should be published only if they are not yet published to the current target. My code is publishing the page and its associated dynamic components properly first time, and If I try to publish the page again the dynamic components are not getting published. But if I unpublish the dynamic components and if I publish the page again, the dynamic components are not getting published. Help me in understanding what went wrong and how to achieve the same.

    private void publishComponents(Component component, TridionCollections.ISet<ResolvedItem> resolvedItems, ComponentTemplate BHTemplate, ComponentTemplate FNTemplate,PublishContext context)
    {
        if (component.Path.Contains("Balloon Help"))
        { 
            var resolvedItem = new ResolvedItem(component, BHTemplate);
            if (!PublishEngine.IsPublished(component, context.PublicationTarget)) resolvedItems.Add(resolvedItem);   
        }
        if (component.Path.Contains("Footnote"))
        {
            var resolvedItem = new ResolvedItem(component, FNTemplate);
            if (!PublishEngine.IsPublished(component, context.PublicationTarget)) resolvedItems.Add(resolvedItem); ;                                

        }
    }    
2
  • Are you sure you are unpublishing it to all the publication targets? Also, can you test your code with a freshly created component rather on existing components? Commented Jul 25, 2014 at 7:41
  • +1 to Dominic's point on what "associated" means here. Dynamic Component Presentations (which are resolved when publishing pages) embedded on a page are different from RenderComponentPresentation(), which can publish CPs outside the default resolving rules. Your code snippet also mentions paths as well, so maybe the relationship is really for a page template rather than a page? How are you calling that publishComponents method? Commented Jul 28, 2014 at 8:48

2 Answers 2

3

It's standard Tridion behaviour that a default publish action only re-publishes (i.e. doesn't publish items that aren't yet published) Well, obviously, the item itself will get published, but not the other items found during resolving.

I'm not sure what you mean by "dynamic components associated with a page". If they are in component presentations on the page, then only that component presentation will be republished, by contrast with a component publish action, which would publish all dynamic renderings of the component.

Tridion has an extensibility point specifically for solving this kind of problem. If you look in the documentation for Custom Resolvers, you will find information about how you can control the resolving process.

1
  • Well, republish is standard except for pages resolving the embedded DCPs on them (with just the explicit templates you mention) and "Dynamic" Component Templates, which queue up all Components based on the same schemas. :-) Commented Jul 28, 2014 at 8:21
3

Your case is standard Tridion behavior with one exception: normally Tridion will publish the dynamic component presentation every time you publish the page. If I understand you correctly, your requirement is to ONLY publish the DCP if it is not published.

I would recommend to publish the page normally, and create a custom resolver which removes the DCP from the list of items to be published if it is already published.

Mind you, I think the requirement itself is a bit odd. What if the component has changed since it was published the last time? Are you sure you don't want to publish it in that case? And why is it so important to not republish the DCP anyway?

Your Answer

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

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