Wednesday, January 25, 2012

Specifying Template Pages for Categories and Products


Category and product items create a navigational framework for customers. You can display categories and products on your commerce site using JSPs.

Rather than requiring you to create a separate JSP for each page on your commerce site, ATG Commerce enables you to create template pages that are filled in dynamically. For example, you could have a single template page for displaying any product. This page would have little or no static content; when the user selects a product, the page is filled in dynamically with information stored in the product’s properties. For example, the following JSP segment uses the ProductLookup servlet bean to display the current product, along with an image and a description.

<dsp:droplet name="/atg/commerce/catalog/ProductLookup">
<dsp:param param="itemId" name="id"/>
<dsp:oparam name="output">
  <p><b><dsp:valueof param="element.displayName"/></b>
  <p><dsp:getvalueof id="img13" param="element.smallImage.url"
          idtype="java.lang.String">
<dsp:img src="<%=img13%>"/>
</dsp:getvalueof>
  <dsp:valueof param="element.description"/>
</dsp:oparam>
</dsp:droplet>

You specify the template to use as a property of the category or product. This enables you to display any item without knowing in advance what template the item uses. For example, the following portion of a JSP uses a CategoryLookup servlet bean to retrieve the current category, and a ForEach servlet bean to create links to all of the child products of the category. The URL for each link is found by looking at the template.url property of the product being linked to.

<dsp:droplet name="/atg/commerce/catalog/CategoryLookup">
<dsp:param param="itemId" name="id"/>
<dsp:oparam name="output">
 <dsp:droplet name="/atg/dynamo/droplet/ForEach">
   <dsp:param param="element.childProducts" name="array"/>
   <dsp:oparam name="outputStart">
   <p><b>Child Products:</b>
   </dsp:oparam>
   <dsp:oparam name="output">
   <dsp:getvalueof id="a21" param="element.template.url"
        idtype="java.lang.String">
<dsp:a href="<%=a21%>">
   <dsp:valueof param="element.displayName"/>
   <dsp:param param="element.repositoryId" name="itemId"/>
   </dsp:a></dsp:getvalueof>
   </dsp:oparam>
 </dsp:droplet>
</dsp:oparam>
</dsp:droplet>

No comments:

Popular Posts