Publishing a component which has multiple dynamic templates will usually result in all the possible dynamic component presentations being published to the broker.
When you create a DCT with the option to place the item on a page, a content editor may not want to publish the components directly, simply relying on the Page publish to do the right thing. We could consider three possible desired publishing scenarios:
- That publishing the page should only cause the static component presentations to be rendered, (plus whatever CD code is necessary to display the dynamic ones)
- That 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 usual component publishing semantics are followed,
and all dynamic renderings will go to the broker.
Tridion’s default behaviour appears to be scenario 2), whereas my experience is that often what you want is scenario 3), giving you a complete and
consistent view of any given component on the CD side.
What is the best way to implement scenario 3 (including getting unpublish to work correctly)?
In my opinion, the best answer for your question is to implement a custom Resolver that would include the required Dynamic Component Presentations. I would be wary of doing anything when unpublishing, as sometimes you may want to keep the DCPs after unpublishing a given page (for “latest news” type of functionality or any other sort of dynamic queries), but the code sample below would make it simple for you to adapt if you need to unpublish all DCPs.
Warning: Below code is not production-tested.
You would now need to add this to the GAC and modify [Tridion]\Config\Tridion.ContentManager.Config so this Resolver is called after every resolve action (under resolving/mappings for every item type).