The template() method

This method allows you to split a JSP page into elements which can be included into other JSP pages using the include() method.

The method can also be used for conditional controls based on page elements of xmlpages.

Parameters:

Name Description
java.lang.String element The name of the element that should be included, if the JSP page is included using the include() method.

Parameters:

 

Name Description
java.lang.String elementlist The names of page elements which are checked on the current xmlpage.
java.lang.boolean checkall Must be set to true, if all elements in the list should be checked.

Parameters:

 

Name Description
java.lang.String element See above
java.lang.String elementlist See above
java.lang.boolean checkall See above

Example usage:

A JSP template page holding two elements "head" and "foot":

<%
org.opencms.jsp.CmsJspActionElement cms = 
new org.opencms.jsp.CmsJspActionElement(pageContext, request, response);

if (cms.template("head")) {%>
<html>
<body>

This is the template head.
<hr>

<!-- Main page body starts here -->
<% } %>

<% if (cms.template("foot")) { %>
<!-- Main page body ends here -->

<hr>
This is the template foot.

</body>
</html>
<% } %>

Conditional control, display the code if the page element "body" does exist:

<%
org.opencms.jsp.CmsJspActionElement cms = 
new org.opencms.jsp.CmsJspActionElement(pageContext, request, response);

if (cms.template("body"), true) {%>

This code is only displayed if the page element "body" exists

<% } %>