6

In my initial DD4T + SmartTarget 2014 integration solution (http://www.tridiondeveloper.com/dd4t-and-sdl-smarttarget-2014-integration) I was trying to achieve something similar to the DefaultComponentPresentationRenderer.RenderComponentPresentations(), but for SmartTarget, where you pass in the Region name. However, I ran into an issue where once we get the DCPs out of SmartTarget, we need to send them through to the appropriate View or Controller/Action as per the Component Template metadata (see RenderComponentPresentation method here: https://code.google.com/p/dynamic-delivery-4-tridion/source/browse/branches/web-assembly/dotnet/DD4T.Mvc/Html/DefaultComponentPresentationRenderer.cs).

The problem is that in the context of DCPs, DD4T actually doesn't seem to publish a ComponentPresentation model, it publishes only the Component. The IComponentPresentation is actually only available when using the ComponentPresentationRenderer in context of a Page. (See raw XMLs coming out of DD4T: when rendering the Page, we get <Page> with <ComponentPresentation> elements, and those have <Template> and <Component> elements. However, when publishing a DCP standalone the XML only has the <Component> element and not info about the CT.)

This works fine for 99% of the cases since in the stand-alone DCP (pageless) scenarios, our application logic dictates which Controller, Action and View to use: the editor doesn't need control in this case. However, with the "helper" approach to SmartTarget, we actually need the CP object, the component doesn't suffice.

My question is: from a purest and cleanest architecture perspective, should DD4T TBBs be modified to publish the Component Presentation (in the Dynamic case) instead of just the Component, or is there another way to retrieve the Component Template metadata (or title) from a DD4T DCP?

2 Answers 2

5

I ran into the same issue. You can solve it now by extending/adjusting the existing ComponentFactory and ComponentProvider to return a ComponentPresentation instead of only a Component. It's not that hard. You have to create a ComponentTemplate object yourself. Ping me if you want the adjusted Factory and Provider.

Actually, the ComponentTemplate title is stored in the Broker Database. You can retrieve it using the following code:

        using (ItemTypeCriteria componentTemplateCriteria = new ItemTypeCriteria(32))
        {
            using(ItemReferenceCriteria itemReferenceCriteria = new ItemReferenceCriteria(3148))
            {
                using(PublicationCriteria inPublicationCriteria = new PublicationCriteria(9))
                {
                    var itemTypeAndIdCriteria = CriteriaFactory.And(componentTemplateCriteria, itemReferenceCriteria);
                    var specificCTCriteria = CriteriaFactory.And(itemTypeAndIdCriteria, inPublicationCriteria);
                    var result = new Query(specificCTCriteria).ExecuteEntityQuery();

                    if (result != null && result.Count() > 0)
                    {
                        var ctTitle = result.FirstOrDefault().Title;
                    }
                }
            }
        }

This has of course a performance impact.

4

You're right - this is our only major design flaw when we designed dd4t; we didn't carefully consider all the cases when working with DCP's. The same problem occurs in the experience manager when you want to make DCP's editable, in many cases you have to guess which template was used.

The java version has a backdoor as the components that the factory produces are of type DynamicComponent (not GenericComponent) which has a handle to the tridion dcp model and then therefor access what the broker knows as well. The dotnet version however has no such backdoor that i know of.

I think our safest bet is to branch dd4t to have a "component presentation" level publishing of dcps instead of "component", which should be a fairly simple and small set of updates (publishing, factory, controller dispatching).

1
  • The Broker actually doesn't seem to store the component template title anywhere in the DB either. And you can only do a template criteria by ID to get a list of component. So my conclusion is that we must publish out this info in the xml ourselves, whether java or dotnet Sep 2, 2014 at 17:11

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.