#sectionList
The system object: #sectionList is available in the section templates which are used by the sections of a CMS_INPUT_CONTENTAREALIST input component. In other words: if a section in a CMS_INPUT_CONTENTAREALIST input component is rendered the system object is available in the referenced section template of the section.
If #sectionList is used in a section template and this is rendered outside of CMS_INPUT_CONTENTAREALIST the return is null. In addition, an error is displayed in the preview/generation log:
ERROR: Expression delivers 'null'
inside of: Template 'commonTemplate' (id=671145)
inside of: $CMS_VALUE(#global.page.body("content"))$ - at 4, 1
inside of: Template 'calSection' (id=749042)
inside of: $CMS_VALUE(#sectionList)$ - at 2, 1
Therefore it is recommended, before using the system object #sectionList , to check whether it is null or not:
$CMS_IF(!#sectionList.isNull)$
...
$CMS_END_IF$
The two intended uses of #sectionList are:
- Determination whether the rendered section is located in a CMS_INPUT_CONTENTAREALIST or not
- Determine the number of sections entered in a CMS_INPUT_CONTENTAREALIST
The invocation of $CMS_VALUE(#sectionList)$ (without method invocation) results in an endless loop which is logged in the preview/generation log: |
ERROR: endless loop in template?
inside of: Template 'commonTemplate' (id=749041)
inside of: $CMS_VALUE(pt_cal)$ - at 7, 3
inside of: Template 'calSection' (id=749042)
inside of: $CMS_VALUE(#sectionList)$ - at 2, 1
inside of: Template 'calSection' (id=749042)
inside of: $CMS_VALUE(#sectionList)$ - at 2, 1
...
The system object: #sectionList is not available for the output of a CMS_INPUT_CONTENTAREALIST input component with a $CMS_FOR(...)$ instruction! The output of the number of sections in the input component can however also be realised in the instruction with .size : |
$CMS_FOR(w, pt_cal)$
$CMS_VALUE(#for.index + 1)$/$CMS_VALUE(pt_cal.size)$: $CMS_VALUE(w)$
$CMS_END_FOR$
The individual invocations and their meaning:
Invocation | Meaning | Return data type |
---|---|---|
#sectionList.isNull | Is the section just rendered part of a CMS_INPUT_CONTENTAREALIST input component or not. | Boolean |
#sectionList.size | Number of sections in a CMS_INPUT_CONTENTAREALIST input component. | |
Examples of #sectionList
Several examples of use of the instruction within templates are shown in the following. The examples are intended to clearly show the specific effect of the instruction and provide help for the template developer when creating their own templates.
The examples displayed here must be adjusted for use within a project! For example, variable names must be changed to the specific variable names of the project in which the instruction is to be used. |
1st Example: Numbered output of the sections
Definition of the CMS_INPUT_CONTENTAREALIST input component (form):
<CMS_MODULE>
<CMS_INPUT_CONTENTAREALIST name="pt_cal">
<LANGINFOS>
<LANGINFO lang="*" label="Content Area List"/>
<LANGINFOS>
</CMS_INPUT_CONTENTAREALIST>
</CMS_MODULE>
Invocation of the input component (HTML presentation channel):
$CMS_VALUE(pt_cal)$
Definition of the section template (form):
<CMS_MODULE>
<CMS_INPUT_TEXT name="st_text">
<LANGINFOS>
<LANGINFO lang="*" label="Text"/>
<LANGINFOS>
</CMS_INPUT_TEXT>
</CMS_MODULE>
Numbered output in the section template (HTML presentation channel):
<CMS_HEADER />
$CMS_IF(!#index.isNull && !#sectionList.size.isNull)$
$CMS_VALUE(#index + 1)$/$CMS_VALUE(#sectionList.size)$:
$CMS_END_IF$
$CMS_VALUE(st_text)$
<br>
Apart from the value of the text input component the example also outputs the index (increased by one) and the total number of sections (e.g. 1/3).
Output:
1/3: 1. Section
2/3: 2nd Section
3/3: 3rd Section