The most common piece of web content is a datafile. Datafiles store various types of information and (usually) are  displayed by Region Templates (typically of type jspx).

When we code our Region Templates, one of the most frequent questions that arises is this:

How can I get a particular metadata field associated with the datafile I am trying to display?

The answer is straight forward:

Make an IdcService call to DOC_INFO and then iterate over the metadata.

This could be easily achieved by using the Site Studio <wcm:metadata> Tag. The only problem here is that if you follow the example from the documentation, then you would have to use a for-each construct to get to your metadata:
<wcm:metadata contentID="${wcmContext.placeholder.dataFile}" var="metadata"/>
<c:forEach var="metadatarow" items="${metadata.resultSets.DOC_INFO.rows}">
<h5>${metadatarow.dDocTitle}</h5>
</c:forEach>
Seems a bit clunky, doesn't it?

Luckily, there is a more convenient way of getting the desired effect without needing extra tags, and honestly, it just makes more sense:
<wcm:metadata contentID="${wcmContext.placeholder.dataFile}" var="metadata"/>
<h5>${metadata.resultSets.DOC_INFO.rows[0].dDocTitle}</h5>
With this approach, you make your Region Templates smaller in size and make your code look logically appealing.

Happy coding.
 


Comments




Leave a Reply


Redstone Content Solutions