jan-h
5/8/2014 - 8:27 AM

SDL SmartTarget tag demo of variables in the promtion query in a SDL SmartTarget enabled page. This is ASPX code. See https://gist.github.co

SDL SmartTarget tag demo of variables in the promtion query in a SDL SmartTarget enabled page. This is ASPX code. See https://gist.github.com/jhorsman/8363387 for the JSP version.

<%@ Page Title="SDL SmartTarget tag demo" Language="C#" %>
<%@ Register Assembly="Tridion.SmartTarget" Namespace="Tridion.SmartTarget.Web.UI" TagPrefix="smarttarget" %>
<%@ Import Namespace="System.Web" %>

<!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 controls for promotions. There are more SmartTarget controls in the SmartTarget library.</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 ASPX source of this demo!</li>
    </ul>
</p>
<hr/>
	<smarttarget:Query runat="server" view="home" publication="tcm:0-69-1" allowDuplicates="true">
        <blockquote>
            <b>&lt;smarttarget:query&gt;</b> start of the query<br/>
		    <smarttarget:Promotions runat="server" Region="Sidebar" MaxItems="10"> 
                <ItemTemplate> 
					<blockquote>
						<b>&lt;smarttarget:promotions&gt;</b> looping through promotions<br/>
                        <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: <%# ((Tridion.SmartTarget.Query.Promotion) Container.DataItem).PromotionId %><br/></li>
									<li>promotion.Name: <%# ((Tridion.SmartTarget.Query.Promotion) Container.DataItem).Name %><br/></li>
									<li>promotion.Title: <%# ((Tridion.SmartTarget.Query.Promotion) Container.DataItem).Title %><br/></li>
									<li>promotion.Region: <%# ((Tridion.SmartTarget.Query.Promotion) Container.DataItem).Region %><br/></li>
									<li>promotion.Slogan: <%# ((Tridion.SmartTarget.Query.Promotion) Container.DataItem).Slogan %><br/></li>
                                </ul>
								<blockquote>
									<b>&lt;smarttarget:promotionalItems&gt;</b> looping through promotional items<br/>
	                                <smarttarget:PromotionalItems runat="server"> 
		                                <ItemTemplate>
                                            <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: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).PromotionId %></li>
                                                            <li>region: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).Region %> </li>
                                                            <li>componentUri: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).ComponentUri %></li>
                                                            <li>templateURI: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).TemplateUri %></li>
                                                        </ul>
                                                        <ul>
                                                            <li>publication id: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).ComponentUri.PublicationId %></li>
                                                            <li>component id: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).ComponentUri.ItemId %></li>
                                                            <li>template id: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).TemplateUri.ItemId %></li>
                                                        </ul>
                                                        <ul>
                                                            <li>publicationtitle from item attributes: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("publicationtitle") %></li>
                                                            <li>item attributes
                                                                <ul>
                                                                        <li>categories: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("categories") %><br /></li>
																		<li>componentname: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("componentname") %><br /></li>
																		<li>componentid: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("componentid") %><br /></li>
																		<li>
																			componentpresentation: <br />
																			<pre><%# HttpUtility.HtmlEncode(((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("componentpresentation") )%></pre>
																		</li>
																		<li>publicationid: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("publicationid") %><br /></li>
																		<li>publicationtitle: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("publicationtitle") %><br /></li>
																		<li>schemaid: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("schemaid") %><br /></li>
																		<li>schematitle: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("schematitle") %><br /></li>
																		<li>secondid: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("secondid") %><br /></li>
																		<li>templateid: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("templateid") %><br /></li>
																		<li>templatetitle: <%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).GetAttribute("templatetitle") %><br /></li>
                                                                </ul>
                                                            </li>
                                                        </ul>
                                                        <ul>
                                                            <li>
																<a href="http://odata.your-staging-server/odata.svc/ComponentPresentations(PublicationId=<%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).ComponentUri.PublicationId %>,ComponentId=<%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).ComponentUri.ItemId %>,TemplateId=<%# ((Tridion.SmartTarget.Query.Item) Container.DataItem).TemplateUri.ItemId %>)/PresentationContent/value"
																	target="_new">
																	Component Presentation on CD webservice
																</a>
															</li>
                                                        </ul>
                                                </blockquote>
                                            </blockquote>
										</ItemTemplate>
		                            </smarttarget:PromotionalItems>
								</blockquote>
                            </blockquote>
                        </blockquote>
					</blockquote>
                </ItemTemplate>
                <FallbackContent>
					<blockquote>
						<b>&lt;smarttarget:promotions&gt;</b> looping through promotions<br/>
						<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>
					</blockquote>
                </FallbackContent>
            </smarttarget:Promotions>
        </blockquote>
    </smarttarget:Query>
</body>
</html>