EL functions provided by OpenCMS taglib

From OpenCms Wiki
(Difference between revisions)
Jump to: navigation, search
m
 
(6 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
Just declare the taglib as usual:
 
Just declare the taglib as usual:
  
  <nowiki><%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %></nowiki>
+
  <source lang="xml"><%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %></source>
  
 
=== cms:vfs ===
 
=== cms:vfs ===
Line 11: Line 11:
  
 
  ${cms:vfs(pageContext).context.locale}
 
  ${cms:vfs(pageContext).context.locale}
 +
 +
The CmsJspVfsAccessBean provides some lazyly loaded maps.
 +
 +
==== Resouces ====
 +
 +
<source lang="xml">
 +
<c:if test="${cms:vfs(pageContext).exists['/checkme.html']}" >
 +
 +
  ${cms:vfs(pageContext).resource['/checkme.html'].rootPath}   
 +
 +
</c:if>
 +
</source>
 +
 +
The objects returned as map values are of type [http://www.opencms.org/javadoc/core/index.html?org/opencms/file/CmsResource.html CmsResource], which is either [http://www.opencms.org/javadoc/core/index.html?org/opencms/file/CmsFile.html CmsFile] or [http://www.opencms.org/javadoc/core/index.html?org/opencms/file/CmsFolder.html CmsFolder].
 +
 +
 +
===== Properties =====
 +
 +
You can use two maps, one for non-searched and second for searched property values. Searched means that if the property is not set for the resource, its parent folders are searched.
 +
 +
Title property of the "/index.html" resource: ${cms:vfs(pageContext).property['/index.html']['Title']}
 +
 +
Title property of the "/index.html" resource (searched): ${cms:vfs(pageContext).propertySearch['/index.html']['Title']}
 +
 +
Similar effect can be achieved in page templates using the cms:property tag:
 +
<source lang="xml">
 +
<h1><cms:property name="Title" file="search" escapeHtml="true" /></h1>
 +
</source>
 +
 +
==== XML content ====
 +
 +
The returned map values are of type [http://www.opencms.org/javadoc/core/index.html?org/opencms/jsp/util/CmsJspContentAccessBean.html CmsJspContentAccessBean].
 +
 +
Example of getting the value of a <Title> XML tag in a specified file:
 +
 +
<source lang="xml">
 +
<c:out value="${cms:vfs(pageContext).xml['/text.xml'].value['Title']}" />
 +
</source>
 +
Example of a template detecting if the page element <body2> exists in the current file:
 +
 +
<source lang="xml">
 +
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
 +
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 +
...
 +
<c:if test="${cms:vfs(pageContext).xml[cms:vfs(pageContext).context.uri].hasValue['body2']}">
 +
  <cms:include element="body2" editable="true"/>
 +
</c:if>
 +
</source>
  
 
=== cms:convertDate ===
 
=== cms:convertDate ===
Line 24: Line 72:
 
   pattern="yyyy-MM-dd HH:mm:ss" />
 
   pattern="yyyy-MM-dd HH:mm:ss" />
 
</source>
 
</source>
 +
 +
=== cms:getCmsObject ===
 +
 +
Returns the current OpenCms user context form the page context.
 +
 +
=== cms:convertLocale ===
 +
 +
Allows conversion of Objects to Locales.
 +
Can also handle Strings that are locales, or Locales itself.
 +
If no valid locale is provided, the OpenCms default locale is returned.
 +
 +
=== cms:stripHtml ===
 +
 +
Strips all HTML markup from the given input.
 +
 +
=== cms:trimToSize ===
 +
 +
Returns a substring of the input, which is not longer then the given int value.
 +
 +
  ${cms:trimToSize('aaabbb',3)}
 +
 +
=== cms:convertUUID ===
 +
 +
Allows conversion of String values to CmsUUIDs.  Can also handle byte[] that are CmsUUIDs, or CmsUUID itself.
 +
 +
=== cms:getRequestParam ===
 +
 +
Returns the value of a parameter from a String that is formatted for a GET request.
 +
 +
=== cms:getRequestLink ===
 +
Returns the link without parameters from a String that is formatted for a GET request.
 +
 +
=== cms:escape ===
 +
Encodes a String in a way that is compatible with the JavaScript escape function.
 +
 +
=== cms:unescape ===
 +
 +
Decodes a String in a way that is compatible with the JavaScript unescape function.
 +
 +
[[Category:Developing in OpenCms ]]

Latest revision as of 18:01, 4 July 2011

The OpenCMS taglib provides tags, but also functions. You can see their definition in the WEB-INF/opencms.tld file, the functions themselves are provided by the CmsJspElFunctions class.

Just declare the taglib as usual:

<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>

Contents

cms:vfs

Provides access to VFS (Virtual File System), returns an instance of org.opencms.jsp.util.CmsJspVfsAccessBean. Example:

${cms:vfs(pageContext).context.locale}

The CmsJspVfsAccessBean provides some lazyly loaded maps.

Resouces

 <c:if test="${cms:vfs(pageContext).exists['/checkme.html']}" >
 
   ${cms:vfs(pageContext).resource['/checkme.html'].rootPath}    
 
 </c:if>

The objects returned as map values are of type CmsResource, which is either CmsFile or CmsFolder.


Properties

You can use two maps, one for non-searched and second for searched property values. Searched means that if the property is not set for the resource, its parent folders are searched.

Title property of the "/index.html" resource: ${cms:vfs(pageContext).property['/index.html']['Title']}
Title property of the "/index.html" resource (searched): ${cms:vfs(pageContext).propertySearch['/index.html']['Title']}

Similar effect can be achieved in page templates using the cms:property tag:

 <h1><cms:property name="Title" file="search" escapeHtml="true" /></h1>

XML content

The returned map values are of type CmsJspContentAccessBean.

Example of getting the value of a <Title> XML tag in a specified file:

 <c:out value="${cms:vfs(pageContext).xml['/text.xml'].value['Title']}" />

Example of a template detecting if the page element <body2> exists in the current file:

<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<c:if test="${cms:vfs(pageContext).xml[cms:vfs(pageContext).context.uri].hasValue['body2']}">
   <cms:include element="body2" editable="true"/>
</c:if>

cms:convertDate

Allows conversion of Long values to Dates. For example to display the time of last modification of a page:

<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
...
 <f:formatDate 
  value="${cms:convertDate(cms:vfs(pageContext).resource[cms:vfs(pageContext).context.uri].dateLastModified)}" 
  pattern="yyyy-MM-dd HH:mm:ss" />

cms:getCmsObject

Returns the current OpenCms user context form the page context.

cms:convertLocale

Allows conversion of Objects to Locales. Can also handle Strings that are locales, or Locales itself. If no valid locale is provided, the OpenCms default locale is returned.

cms:stripHtml

Strips all HTML markup from the given input.

cms:trimToSize

Returns a substring of the input, which is not longer then the given int value.

 ${cms:trimToSize('aaabbb',3)}

cms:convertUUID

Allows conversion of String values to CmsUUIDs. Can also handle byte[] that are CmsUUIDs, or CmsUUID itself.

cms:getRequestParam

Returns the value of a parameter from a String that is formatted for a GET request.

cms:getRequestLink

Returns the link without parameters from a String that is formatted for a GET request.

cms:escape

Encodes a String in a way that is compatible with the JavaScript escape function.

cms:unescape

Decodes a String in a way that is compatible with the JavaScript unescape function.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox