The docs contain a detailed TCDL reference for SmartTarget tags, however I am not rendering my pages at publish time, and want to use the JSP tag libs directly in my page view code. Does anyone have some examples to get me started - I would have guessed to just use a similar syntax to the TCDL, but there seems to be some differences (TCDL has a region tag, but the taglib not, for example).
2 Answers
The shortest possible SmartTarget promotions implementation with JSP tags is as follows. This indeed looks a lot like the TCDL tags.
<smarttarget:query siteEditTagName="span" publication="tcm:0-72-1">
<smarttarget:promotions region="Homepage Banners" maxItems="1">
<smarttarget:itemTemplate>
<smarttarget:promotionalItems>
<smarttarget:itemTemplate>
<span>
<!-- Start Promotion: { "PromotionID": "${item.promotionID}", "RegionID" : "${item.region}"} -->
<tridion:ComponentPresentation pageURI="tcm:72-6212-64" componentURI="${item.componentUri}" templateURI="${item.templateUri}"/>
<!-- End Promotion -->
</span>
</smarttarget:itemTemplate>
</smarttarget:promotionalItems>
</smarttarget:itemTemplate>
</smarttarget:promotions>
</smarttarget:query>
Here are some other examples, all are showing the same thing: one SmartTarget region which queries for promotions, Eperience Manager Markup and three fallback component presentations.
- Full JSP example: https://gist.github.com/83e45c851b63481e39bb This the
- TCDL source: https://gist.github.com/3b5c48c3a5ea5d5e12b8 The
- Dreamweaver source: https://gist.github.com/6053b09d0ccbd31e058b And
- The same thing in .NET controls instead of JSP tags https://gist.github.com/70d569023e78081c3b57
The <tcdl:region>
tag in the Dreamweaver TBB creates the TCDL source. The TCDL tags create the JSP tags. The JSP tags creates the HTML output with XPM markup (example).
There is a TLD file on the CD layout (Content Delivery\java\web\tld) which provides the list of tags, their attributes, and remarks explaining the purpose of each of them.
Combine that with the API documentation available on LiveContent (login required) and you should have a complete picture on how to use the tags in your web application.