To render SEO tags on a page, you pass the value of the key
property of an SEOTags
item to the RQLQueryRange
servlet bean. This servlet bean finds an SEOTags
item with that key
value and uses the other properties of the item to supply the content for the tags.
The following example queries the repository for an item whose key
property has the value "featured"
. The other properties of the returned item are then used to render the <title>
tag and <meta>
tags.
<dsp:droplet name="/atg/dynamo/droplet/RQLQueryRange"> <dsp:param name="repository" value="/atg/seo/SEORepository" /> <dsp:param name="itemDescriptor" value="SEOTags" /> <dsp:param name="howMany" value="1" /> <dsp:param name="mykey" value="featured" /> <dsp:param name="queryRQL" value="key = :mykey" /> <dsp:oparam name="output"> <title><dsp:valueof param="element.title"/></title> <dsp:getvalueof var="description" param="element.description"/> <dsp:getvalueof var="keywords" param="element.keywords"/> <meta name="description" content="${description}" /> <meta name="keywords" content="${keywords}"/> </dsp:output> </dsp:droplet>
Note that the howMany
parameter is set to 1 to ensure that only one set of tags is rendered. In general, you should make sure that the key
property of each SEOTags
item is unique.
The approach shown in the example above is useful if you have multiple pages using the same tag. You can include this servlet bean call in each of these pages, and they will all create tags use the SEOTags
item whose key is "featured"
.
If you have pages that each require a unique set of tags (and therefore a unique SEOTags
item), a better approach is to set each SEOTags
item’s key
to a page-specific portion of the page URL, such as the servlet path. The servlet path does not include the protocol, domain, port, context root, or query arguments, and typically looks similar to this:
/browse/category.jsp
In the servlet bean call, you dynamically evaluate the servlet path and pass that value to the servlet bean as the key
. This approach allows you to use the same call in multiple pages, rather than having to hard-code the key
in each one individually.
The following example illustrates this approach. A parameter named pageURL
is set to the servlet path of the originating request. The pageURL
parameter is then used to construct RQL to query the repository for an SEOTags
item whose key
value is that servlet path.
<dsp:droplet name="/atg/dynamo/droplet/RQLQueryRange"> <dsp:param name="repository" value="/atg/seo/SEORepository" /> <dsp:param name="itemDescriptor" value="SEOTags" /> <dsp:param name="howMany" value="1" /> <dsp:param name="pageURL" bean="/OriginatingRequest.servletPath" /> <dsp:param name="queryRQL" value="key = :pageURL" /> ... </dsp:droplet>
Note that the key should be based on the actual (dynamic) page URL, not the static URL created through the URL recoding feature. When a spider accesses a page through a recoded (static) URL, the static URL is translated by the SEO jump servlet back to its dynamic equivalent. So the page is actually served using the dynamic URL.