When DCPs are placed on a page in Tridion, how can you guarantee that all dynamic component renderings will be published with the page?

Publishing a component that has several dynamic templates usually leads to the publication of all possible dynamic component presentations for the broker.

When you create a DCT with the ability to place an element on a page, the content editor may not want to publish the components directly, simply relying on the publication of the page to do the right thing. We could consider three possible publishing scenarios:

  • The publication of this page should lead to the visualization of representations of static components (plus any CD code is necessary to display dynamic).
  • In addition to static CPs, any dynamic CPs should be published. Other possible dynamic renderings of the same component are not published.
  • If a dynamic CP is published, the standard semantics of component publishing are applied, and all dynamic rendering will go to the broker.

Tridion's default behavior looks like a 2) scenario, while my experience is that often what you need is a 3) scenario, giving you a complete and consistent look at any given component on the CD side.

What is the best way to implement scenario 3 (including making the publication work incorrectly)?

+6
source share
2 answers

In my opinion, the best answer to your question is the introduction of a custom Resolver, which will include the required dynamic presentation of components. I would be wary of doing something when you weren’t publishing, because sometimes you might want to save DCP after publishing this page (for the type of “breaking news” or any other dynamic queries), but the code example below would do it is easy for you to adapt if you need to unpublish all DCPs.

Warning: the code below is not tested for production.

using Tridion.ContentManager; using Tridion.ContentManager.CommunicationManagement; using Tridion.ContentManager.ContentManagement; using Tridion.ContentManager.Publishing; using Tridion.ContentManager.Publishing.Resolving; public class IncludeDynamicComponentPresentations : IResolver { public void Resolve( IdentifiableObject item, ResolveInstruction instruction, PublishContext context, Tridion.Collections.ISet<ResolvedItem> resolvedItems) { if (!(instruction.Purpose == ResolvePurpose.Publish || instruction.Purpose == ResolvePurpose.RePublish)) { // Do nothing more when unpublishing return; } Session session = item.Session; foreach (ResolvedItem resolvedItem in resolvedItems) { // Only do something if we're dealing with a page if (!(resolvedItem.Item is Page)) continue; Page page = (Page)resolvedItem.Item; if (page.ComponentPresentations.Count > 0) { UsingItemsFilter filter = new UsingItemsFilter(session); filter.InRepository = page.ContextRepository; filter.ItemTypes = new[] { ItemType.ComponentTemplate }; foreach (ComponentPresentation cp in page.ComponentPresentations) { // Find all component templates linked to this component schema Schema schema = cp.Component.Schema; foreach (ComponentTemplate ct in schema.GetUsingItems(filter)) { if (!ct.Id.Equals(cp.ComponentTemplate.Id)) { if (ct.IsRepositoryPublishable) { resolvedItems.Add(new ResolvedItem(cp.Component, ct)); } } } } } } } } 

Now you need to add this to the GAC and change [Tridion] \ Config \ Tridion.ContentManager.Config so that this Resolver is called after each permission action (for resolution / mappings for each element type).

+8
source

Perhaps Custom Resolver will help in this situation? This will give you access to all the elements resulting from the publish action, allowing you to change the default behavior.

Here is a good example of this in the SDL Tridion documentation portal, but it basically allows you to create your own recognizer class in .net, where you can implement your own logic.

+3
source

Source: https://habr.com/ru/post/908775/


All Articles