We demonstrate how to access information about the currently rendered container page in a formatter or function provider. The information is useful to, e.g., change styles, hide or show extra information, etc.

The result

If you are offline, you may move or edit the dynamic function shown as result and see how values change.

You may wonder about the container's name: When a container is nested, it's name is generated automatically out of its name, its parents' names and the parents' element ids.
 

Container page information

About the current container

  • Name: 79d2d85c-22ba-11e4-8f7a-d9f74955ba1b-demo-content-container
  • Type: demo-content
  • Width: -1
  • Max Elements: 100

Container page

  • Container Names:
    • documentation-topic-container
    • documentation-content-container
    • fcba6c7f-22b8-11e4-8f7a-d9f74955ba1b-documentation-section-container
    • 79d2d85c-22ba-11e4-8f7a-d9f74955ba1b-demo-content-container
    • b5a54cdf-22bd-11e4-8f7a-d9f74955ba1b-documentation-section-container
  • Container Types:
    • demo-content
    • documentation-content
    • documentation-topic
    • documentation-section

Element Mode:

Mode: false

The element mode is true, if the element have been moved or edited, but the page have not been reloaded yet.
The element mode is false, if the element have not been changed since the last reload of the page.


The content is in a container of type "demo-content", if you are offline, move it and see how values change.
 

Example resources and the interesting spots

Just one resource is interesting for this example: the function provider for the above displayed function. Look at the EL expressions starting with cms.container, cms.page and on the expression cms.edited. These provide the displayed information.

<%@page buffer="none" session="false" trimDirectiveWhitespaces="true" %>
<%@taglib prefix="cms" uri="http://www.opencms.org/taglib/cms"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="margin-bottom-30">
    <div class="headline">
        <h3>Container page information</h3>
    </div>
	<h4>About the current container</h4>
    <ul>
    <li><b>Name:</b> ${cms.container.name}</li>
    <li><b>Type:</b> ${cms.container.type}</li>
    <li><b>Width:</b> ${cms.container.width}</li>
    <li><b>Max Elements:</b> ${cms.container.maxElements}</li>
    </ul>
    
    <h4>Container page</h4>
    <ul>
        <li><b>Container Names:</b>
            <ul>
                <c:forEach var="con" items="${cms.page.names}">
                    <li>${con}</li>
                </c:forEach>
            </ul>
        </li>
        <li><b>Container Types:</b>
            <ul>
                <c:forEach var="con" items="${cms.page.types}">
                    <li>${con}</li>
                </c:forEach>
            </ul>
        </li>
    </ul>
    
    <h4>Element Mode:</h4>
    <p><b>Mode:</b> ${cms.edited}</p>
    <c:if test="${cms.edited}">
        <p>Please reload the current page.</p>
        <p>The element mode is <strong>true</strong>, if the element have been moved or edited, but the page have not been reloaded yet.<br/>
        The element mode is <strong>false</strong>, if the element have not been changed since the last reload of the page.</p>
    </c:if>
    <c:if test="${!cms.edited}">
        <p>The element mode is <strong>true</strong>, if the element have been moved or edited, but the page have not been reloaded yet.<br/>
        The element mode is <strong>false</strong>, if the element have not been changed since the last reload of the page.</p>
    </c:if>
    <c:if test="${cms.container.type == 'demo-content' }">
    	<hr />
    	<em>The content is in a container of type "demo-content", if you are offline, move it and see how values change.</em>
    	<hr />
    </c:if>
</div>
Find out, what OpenCms-specific information is accessible via the cms, an object of type org.opencms.jsp.util.CmsJspStandardContextBean by consulting the JavaDoc.