Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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).

share|improve this answer
    
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 –  Nickoli Roussakov Sep 2 at 17:11

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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