Cms:contentaccess

From OpenCms Wiki
Jump to: navigation, search

Contents

<cms:contentaccess>

(From the javadocs: http://files.opencms.org/javadoc/core/org/opencms/jsp/CmsJspTagContentAccess.html)

Used to access XML content item information from the current open <cms:contentload> tag using JSP page context and the JSP EL.

The tag will create an instance of a CmsJspContentAccessBean that is stored in the selected context. Use the options provided by the bean to access the XML content directly.

For example together with the JSTL, use this tag inside an open tag like this:

 <cms:contentload ... >
     <cms:contentaccess var="myVarName" val="myValueVarName" scope="page" />
     ... other code ...
 </cms:contentload>

The tag is available since OpenCms 7.0.2.

Within this tag, the CmsJspContentAccessBean is exposed:

CmsJspContentAccessBean

(From the javadocs: http://files.opencms.org/javadoc/core/org/opencms/jsp/util/CmsJspContentAccessBean.html)

Allows access to the individual elements of an XML content.

The implementation is optimized for performance and uses lazy initializing of the requested values as much as possible.

The bean exposes some properties (this is not a comprehensive list):

CmsObject:getCmsObject()

Returns the OpenCms user context this bean was initialized with.

CmsFile:getFile()

Returns the raw VFS file object the content accessed by this bean was created from.

String:getFileName()

Returns the site path of the current resource.

Map<String,CmsJspContentAccessValueWrapper>:getValue()

Returns a lazy initialized Map that provides values from the XML content in the current locale. The provided Map key is assumed to be a String that represents the xpath to the value. Usage example on a JSP with the JSTL:

 <cms:contentload ... >
      <cms:contentaccess var="content" />
      The Title: ${content.value['Title']}
 </cms:contentload>

Map<String,List<CmsJspContentAccessValueWrapper>>:getValueList()

Returns a lazy initialized Map that provides Lists of values from the XML content in the current locale. The provided Map key is assumed to be a String that represents the xpath to the value. Use this method in case you want to iterate over a List of values form the XML content. Usage example on a JSP with the JSTL:

 <cms:contentload ... >
     <cms:contentaccess var="content" >
     <c:forEach var="teaser" items="${content.valueList['Teaser']}">
         ${teaser}
     </c:forEach>
 </cms:contentload>
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox