Cms:contentload

From OpenCms Wiki
(Difference between revisions)
Jump to: navigation, search
(Collectors)
 
(6 intermediate revisions by 4 users not shown)
Line 18: Line 18:
  
 
Find more informations about which collector parameters exist and how they work in the source code at ''org.opencms.file.collectors.*'', e.g. ''CmsDefaultResourceCollector''.
 
Find more informations about which collector parameters exist and how they work in the source code at ''org.opencms.file.collectors.*'', e.g. ''CmsDefaultResourceCollector''.
 +
 +
==Collectors==
 +
This section describes a few collectors. You can also find all this in the source code as described above.
 +
*'''allInFolderDateReleasedDesc''': This gets all resources in a folder sorted in descending order by their publish date.
 +
*'''allInFolderDateDesc''': This gets all resources in a folder sorted in descending order by their creation date. Type of resource needed and number can be specified in the collector parameter.
 +
* '''allInSubTreeDateAsc''': Gets all resources in a folder and its subfolders sorted in ascending order by their creation date. The sorting can be adapted in the param attribute.
 +
* '''allInSubTreeDateDesc''': Gets all resources in a folder and its subfolders sorted in descending order by their creation date. The sorting can be adapted in the param attribute.
 +
* '''allInFolderPriorityDateAsc''' and '''allInFolderPriorityDateDesc''' - Get all resources in a folder sorted by collector.priority property value, then the release date - see [http://files.opencms.org/javadoc/core/org/opencms/file/collectors/CmsPriorityResourceCollector.html CmsPriorityResourceCollector.allInFolderPriorityDate() javadoc] - this is what you want for news, conferences etc., they are ordered by release day, and the order can be manipulated using the priority
 +
 +
== Params ==
 +
The param attribute defines which files are listed give you also some power to sort the resulting list.
 +
 +
The sytax is the following:
 +
<code lang="html4strict">
 +
<cms:contentload param="<the target cms folder>|name-of-your-open-cms-content-type|<how many items to display>|<optional atribute used for the sort compare>" [rest of attributes]>
 +
</code>
 +
 +
For example:
 +
This will display all items of the type es-calendar-entry in the folder ${calendar.value.Source} and be sorted by the date attribute of the file (it can be mapped from the input field attributes of the content type).
 +
<code lang="html4strict">
 +
<cms:contentload param="${calendar.value.Source}|es-calendar-entry|${numberOfEvents}|collector.date" [rest of attributes]>
 +
</code>
 +
 +
[[Category:Developing in OpenCms ]]

Latest revision as of 09:17, 30 May 2014

There is only a little documentation regarding usage of cms:contentload. This document hopes to expand on that.

Contentload is a tag that will let you load a CMS resource as an object, and manipulate it using jsp tags. More detail is available in the documentation included with OpenCms.

Here is an example where an asterisk is used for pattern matching in the param section:

  <cms:contentload collector="allInFolderPriorityDateDesc" param="${opencms.folder}news${*}.html|news|15" editable="true">
    <%-- create a date object from date value --%>	
    <li>
      <a href="<cms:link><cms:contentshow element="${opencms.filename}" /></cms:link>" title="<cms:contentshow element="Title" />"></a>
      <p><cms:contentshow element="Teaser" /></p>
    </li>
  </cms:contentload>

Important note, if you are running OpenCms 7 or newer, use %(opencms.folder), %(opencms.filename), etc, since the macro syntax is now "%()".

Find more informations about which collector parameters exist and how they work in the source code at org.opencms.file.collectors.*, e.g. CmsDefaultResourceCollector.

Collectors

This section describes a few collectors. You can also find all this in the source code as described above.

  • allInFolderDateReleasedDesc: This gets all resources in a folder sorted in descending order by their publish date.
  • allInFolderDateDesc: This gets all resources in a folder sorted in descending order by their creation date. Type of resource needed and number can be specified in the collector parameter.
  • allInSubTreeDateAsc: Gets all resources in a folder and its subfolders sorted in ascending order by their creation date. The sorting can be adapted in the param attribute.
  • allInSubTreeDateDesc: Gets all resources in a folder and its subfolders sorted in descending order by their creation date. The sorting can be adapted in the param attribute.
  • allInFolderPriorityDateAsc and allInFolderPriorityDateDesc - Get all resources in a folder sorted by collector.priority property value, then the release date - see CmsPriorityResourceCollector.allInFolderPriorityDate() javadoc - this is what you want for news, conferences etc., they are ordered by release day, and the order can be manipulated using the priority

Params

The param attribute defines which files are listed give you also some power to sort the resulting list.

The sytax is the following:

<cms:contentload param="<the target cms folder>|name-of-your-open-cms-content-type|<how many items to display>|<optional atribute used for the sort compare>" [rest of attributes]>

For example: This will display all items of the type es-calendar-entry in the folder ${calendar.value.Source} and be sorted by the date attribute of the file (it can be mapped from the input field attributes of the content type).

<cms:contentload param="${calendar.value.Source}|es-calendar-entry|${numberOfEvents}|collector.date" [rest of attributes]>
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox