How to display metadata in the header of the page

  Written by The Jahia Team
 
Developers
   Estimated reading time:
6.6.2.11

After adding values for the metadata "description" and "keywords", the customer would expect to see these values in the meta names tag of the header of his page. However, there are no meta names present.

Cause

The JSP view of the customer's template was not designed to get the values of the metadata description and keywords.

Solution

An example of our ACME Space template has been provided to show the way to get the values of these metadatas and to the way to set the corresponding meta names. Here is this example: ([Jahia 6.6]\tomcat\webapps\ROOT\WEB-INF\var\shared_modules\templates-web-space-1.5.war).

Extract of the view: template.templates-web-space.jsp

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <jcr:nodeProperty node="${renderContext.mainResource.node}" name="jcr:description" inherited="true" var="description"/>
    <jcr:nodeProperty node="${renderContext.mainResource.node}" name="jcr:createdBy" inherited="true" var="author"/>
    <jcr:nodeProperty node="${renderContext.mainResource.node}" name="j:keywords" inherited="true" var="kws"/>
    <c:set var="keywords" value=""/>
    <c:forEach items="${kws}" var="keyword">
        <c:choose>
            <c:when test="${empty keywords}">
                <c:set var="keywords" value="${keyword.string}"/>
            </c:when>
            <c:otherwise>
                <c:set var="keywords" value="${keywords}, ${keyword.string}"/>
            </c:otherwise>
        </c:choose>
    </c:forEach>
    <c:if test="${!empty description}"><meta name="description" content="<c:out value="${description.string}" />" /></c:if>
    <c:if test="${!empty author}"><meta name="author" content="${author.string}" /></c:if>
    <c:if test="${!empty keywords}"><meta name="keywords" content="${keywords}" /></c:if>

    <link rel="stylesheet" type="text/css" href="<c:url value=&#quot;${url.currentModule}/css/print.css&#quot;/>" media="print" />
    <title>${fn:escapeXml(renderContext.mainResource.node.displayableName)}</title>
</head>