OpenCms Documentation

Dynamic functions

 Show GitHub edit links  Hide GitHub edit links
In OpenCms since: 8.0 Valid for OpenCms: 12.0

We show a dynamic function that displays the current date and time. The format is adjustable via element settings.

The result

The following example content is a dynamic function with parameters and settings configured. The function provider displays the parameters and settings and uses them to format a date.

If you are offline, edit the dynamic function and see how its appearance changes. Moreover, you can add the dynamic function again ("Add content" -> "Dynamic functions" -> "Demo dynamic function".


Dynamic Function Demo.

Oct 23, 2021, 10:57:41 AM
  • Format: both
  • Style: medium
  • locale: en_US

Example resources and interesting spots

A dynamic function consists of two main parts: the function itself and a JSP, that is kind of a formatter for the function.

The function itself is an XML content where the JSP, element settings and parameters passed to the JSP are configured. Moreover, the containers where the function can be rendered are defined in the function content. Below, the function for the above example is shown. It also opens, when you edit the above example.

The second component, the JSP that renders the shown content, can read teh configured parameters and element settings from the function.

Here is the code of the provider from the above example.

<%@page buffer="none" session="false" trimDirectiveWhitespaces="true" %>
<%@taglib prefix="cms" uri=""%>
<%@taglib prefix="c" uri=""%>
<%@taglib prefix="fmt" uri=""%>
<fmt:setLocale scope="page" value="${param.locale}" />
    <%-- Title of the article --%>
    <h4>Dynamic Function Demo.</h4>
        <%-- The text field of the article with image --%>
        <div class="paragraph">
            <jsp:useBean id="date" class="java.util.Date" />
            <%-- Use the setting option to define the format and style of the date time output. --%>
            <c:set var="format"><cms:elementsetting name="format"/></c:set>
            <c:set var="style"><cms:elementsetting name="style"/></c:set>
            <b><fmt:formatDate value="${date}" dateStyle="${style}" type="${format}" /></b>
                <li><b>Format:</b> <cms:elementsetting name="format"/></li>
                <li><b>Style:</b> <cms:elementsetting name="style"/></li>
                <li><b>locale:</b> ${param.locale}</li>

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.