DD4T and SDL SmartTarget 2014 Integration

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

Happy coding!

4 thoughts on “DD4T and SDL SmartTarget 2014 Integration

  1. I have followed the static SmartTargetHelper class but ClaimStore claimStore = AmbientDataContext.CurrentClaimStore; always returns null . Also in your view RenderSmartTargetRegion function is used which is not available

  2. From where I can get the basic-page-view.cshtml & SmartTargetHelper.cs for reference?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>