There are a number of steps required to install SmartTarget and all the required pieces, including FredHopper and the new SmartTarget CD Webservice Extension. Thatâ€™s right; Tridionâ€™s OData Webservice now comes with a SmartTarget extension to grab your Promotionsâ€™ itemsâ€¦ I digress. In this article I am going to assume that youâ€™ve done your homework and read the SDL Live Content documentation regarding the necessary moving parts, wiring and plumbing, and have it all installed. (If youâ€™re looking for an introduction to SmartTarget 2014, have a look at John Winterâ€™s article: A look at SmartTarget 2014). So here weâ€™ll just jump right into answering the question of how to integrate DD4T.NET with SmartTarget 2014 and I will share an MVC HTML Helper Extension class providing us with control to render SmartTargetâ€™s Promotion Items in your DD4T-driven MVC.NET application.
SmartTarget ships with a number of TBBs. The only TBB that we need is Add to SmartTarget added to the Dynamic Component Templates so that the DCPs published using those templates go to Fredhopper as well.
The other shipped TBBs are used to: (a)Â generateÂ the SmartTarget query in the form of TCDL tags and, (b) to transform the element on the Page Template Layout TBB into your Publicationâ€™s Target Output Language. That is, if your Publicationâ€™s Target Language is ASP.NET, then the Deployer transforms TCDL into Tridion SmartTarget User Controls; and if the target language is JSP Scripting, then into JSTL Tags, or if it is REL and youâ€™re pulling fully rendered Pages out of the Broker DB via the OData webserviceÂ (or some other custom means) then keeps the tags as TCDL where the Render Engine Language module does all the work (if youâ€™re not up-to-speed on REL, check out Mr. Priceâ€™s article explaining it: What the REL?! â€“ A simple and very practical use of REL).
Now, let’s look back at the fundamentals of DD4T. Â With this framework we donâ€™t publish any markup from Tridion. Rather we publish the Page and Component models rendered as XML, and transform this XML into markup via Model-View-Controller on the Content Delivery/Presentation server â€“ in other words, we fry, not bake. So the mechanisms provided for â€œbakingâ€ the target language markup are not needed.
In order to render a SmartTarget region on a DD4T page, typically we need to add markup to the Page Razor View, and in this view render a SmartTarget region. Something like this [note lines 10-14 below]:
Note: The markup above is extremely simplified. Normally weâ€™d use layouts and also add XPM markup to the page view. Iâ€™ve only added the XPM markup for the SmartTarget bit.
So it is convenient, then, to add an HTML Helper Extension method, e.g. RenderSmartTargetRegion, that gets our Promotional Items out of FredHopper/SmartTarget and sends them through the business-as-usual MVC rendering process for Component Presentations.
Here is the helper code:
This is the first version of the code, and has not been tested in Production. However, it should give you the idea on the integration approach and example usage of the SmartTarget 2014 API. The next steps are to do some more testing on this bit of logic and add it into the main DD4T code repository. This I will do in due time (or if someone beats me to it, this would be a welcome gesture).