OpenCms Documentation

Meta mappings

 Show GitHub edit links  Hide GitHub edit links
In OpenCms since: 11.0.0 Valid for OpenCms: 11.0.0

Meta mappings enable you to read the information of an element on a container page before the element is rendered. Here, we have two elements. One element contains meta information and defines the meta mappings, the other element on the same page can simply read this information by using EL.

The result

Here you see two elements. The first element shows the meta information of the second one, provided that the second element contains meta information and is chosen with the formatter "Demo article formatter: Meta mappings".

To see the effect on the first formatter, just change the meta information of the second element inline. Optionally you can edit the values in the content editor displayed below. In this case, you need to reload the page.

 

I read the meta information of the element below

The title of the element you have dropped:
The element with meta information

The meta information of the added element is:

Description:
The meta information out of a nested content to illustrate the path for subfolders

Keywords:
demo, meta mappings, formatter configuraiton, meta tag, template JSP

This is the second element containing the mapped meta information which should be displayed by the first element. You can edit the underlined values which will change the first element.

The element with meta information

Description:

The meta information out of a nested content to illustrate the path for subfolders

Keywords:

Further information

 

Example resources and the interesting spots

This is the content editor of the element with meta information: The fields "Title", as well as "Description" and "Keywords" under the subitem "MetaInfo" are mapped. Remember to reload the page after changing the values of the meta mappings in this editor.

Below, you see the formatter configuration. In the tab "Meta mappings", you can find the definitons of the meta mappings.The value of the field "Title" is mapped and can be called by the key "MainTitle".

Note, that the last meta mapping refers to a non-existing path, so the default value is taken.

This is the formatter reading the meta information. To call the mapped value in the field "Title" you need to write ${cms.meta.MainTitle}.

<%@page buffer="none" session="false" taglibs="c,cms" %>
<cms:formatter var="content">

<div style="margin-bottom:30px;">
	<c:choose>
	
	<%-- check if the element added on the page includes the meta mappings of the wanted kind --%>
		<c:when test="${cms.meta.containsMeta}">
		
			<div style="background-color:palegreen; text-align:center;">
				<h3>${content.value.Title}</h3>
				
		<%-- show the meta information mapped with the key "MainTitle" --%>
				<h4>The title of the element you have dropped: <br>
					<span style="background-color:lightgrey">${cms.meta.MainTitle}</span>
				</h4>
				
				<h4>The meta information of the added element is:</h4>
	
		<%-- show the meta information mapped with the keys "Description" and "Keywords" --%>
				<div style="text-align:center;">
					<h4>Description: <br>
						<span style="background-color:lightgrey">${cms.meta.Description}</span>
					</h4>
					<h4>
						Keywords: <br>
						<span style="background-color:lightgrey">${cms.meta.Keywords}</span>
					</h4></div>
			</div>
		</c:when>
		
		<%-- message, when wrong formatter is chosen --%>
		<c:otherwise>
			<div style="vertical-align: middle;background-color:Tomato;height: 100px;">
			<h3 style="text-align:center;line-height: 50px;">You either put the wrong element (without any meta information) or you have chosen the wrong formatter</h3>
			</div>
		</c:otherwise>
	</c:choose>
</div>
</cms:formatter>

You can improve this page

Please contribute your suggestions or comments regarding this topic on our wiki. For support questions, please use the OpenCms mailing list or go for professional support.