Skip to content

Instantly share code, notes, and snippets.

@jhorsman
Last active January 2, 2016 21:29
Show Gist options
  • Save jhorsman/8363387 to your computer and use it in GitHub Desktop.
Save jhorsman/8363387 to your computer and use it in GitHub Desktop.
SDL SmartTarget 2011 SP2 tag demo of variables in the promtion query in a SDL SmartTarget enabled page. This is JSP code, there is a similar user control for ASP .NET. SDL SmartTarget 2011 SP2.
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ page language="java"%>
<%@ page import="java.net.URI" %>
<%@ page import="com.tridion.ambientdata.claimstore.ClaimStore" %>
<%@ page import="com.tridion.ambientdata.AmbientDataContext" %>
<%@ taglib uri="smarttarget" prefix="smarttarget" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>SmartTarget tag demo</title>
</head>
<body>
<h1>SmartTarget tag demo</h1>
<p>
<ul>
<li>Demo of the strucure of SDL SmartTarget tags for promotions. There are more SmartTarget tags in the SmartTarget taglib.</li>
<li>To make this work with your SmartTarget server update the following:
<ul>
<li>publication attribute &lt;smarttarget:query&gt;</li>
<li>region attribute in &lt;smarttarget:promotions&gt;</li>
<li>optional: odata URL</li>
<li>don't forget the settings in smarttarget_conf.xml, look at /Configuration/Fredhopper/Webservice/Server.</li>
</ul>
</li>
<li>To see how multiple promotions are returned, set up multiple promotions...</li>
<li>Do read the JSP source of this demo!</li>
</ul>
</p>
<hr/>
<smarttarget:query view="home" publication="tcm:0-69-1" allowDuplicates="true">
<blockquote>
<b>&lt;smarttarget:query&gt;</b> start of the query<br/>
<smarttarget:promotions region="Sidebar" var="promotion" maxItems="10">
<blockquote>
<b>&lt;smarttarget:promotions&gt;</b> looping through promotions<br/>
<smarttarget:itemTemplate>
<blockquote>
<b>&lt;smarttarget:itemTemplate&gt;</b> item template to apply on each promotion<br/>
<blockquote>
<b>promotion object properties</b>
<ul>
<li>promotion.promotionId: ${promotion.promotionId}<br/></li>
<li>promotion.name: ${promotion.name}<br/></li>
<li>promotion.title: ${promotion.title}<br/></li>
<li>promotion.region: ${promotion.region}<br/></li>
<li>promotion.slogan: ${promotion.slogan}<br/></li>
</ul>
<smarttarget:promotionalItems>
<blockquote>
<b>&lt;smarttarget:promotionalItems&gt;</b> looping through promotional items<br/>
<smarttarget:itemTemplate var="item">
<blockquote>
<b>&lt;smarttarget:itemTemplate&gt;</b> item template to apply on each promotional item<br/>
<blockquote>
<b>item object properties</b>
<ul>
<li>promotionID: ${item.promotionID}</li>
<li>region: ${item.region}</li>
<li>componentUri: ${item.componentUri}</li>
<li>templateURI: ${item.templateUri}</li>
</ul>
<ul>
<li>publication id: ${item.componentUri.publicationId}</li>
<li>component id: ${item.componentUri.itemId}</li>
<li>template id: ${item.templateUri.itemId}</li>
</ul>
<ul>
<li>item attributes
<ul>
<c:forEach var="attr" items="${item.getAttributelist()}">
<c:choose>
<c:when test="${attr.getName()=='componentpresentation'}">
<li>
${attr.getName()}: <br />
<pre>${fn:escapeXml(attr.getValue())}</pre>
</li>
</c:when>
<c:otherwise>
<li>${attr.getName()}: ${attr.getValue()}</li>
</c:otherwise>
</c:choose>
</c:forEach>
</ul>
</li>
</ul>
<ul>
<li><a href="http://odata.your-staging-server/odata.svc/ComponentPresentations(PublicationId=${item.componentUri.publicationId},ComponentId=${item.componentUri.itemId},TemplateId=${item.templateUri.itemId})/PresentationContent/value" target="_new">Component Presentation on CD webservice</a></li>
</ul>
</blockquote>
</blockquote>
</smarttarget:itemTemplate>
</blockquote>
</smarttarget:promotionalItems>
</blockquote>
</blockquote>
</smarttarget:itemTemplate>
<smarttarget:fallbackContent>
<blockquote>
<b>&lt;smarttarget:fallbackContent&gt;</b> fallback content<br/>
This is Fallback content. SmartTaget (Fredhopper query server) did not return any promotions or is not available.<br/>
</blockquote>
</smarttarget:fallbackContent>
</blockquote>
</smarttarget:promotions>
</blockquote>
</smarttarget:query>
<hr/>
<%
ClaimStore claimStore = AmbientDataContext.getCurrentClaimStore();
%>
<p>
<b>Trigger types in claim store</b>
<b>claim URI</b>: taf:claim:ambientdata:definedtriggertypes<br/>
<b>value</b>: <%= claimStore != null ? claimStore.get(URI.create("taf:claim:ambientdata:definedtriggertypes")) : "Claimstore not set" %><br/>
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment