Start page
Start page

Start page / Template development / Template syntax / System objects / #index

#indexAvailable from FirstSpirit Version 4.0

The system object: #index is available in section templates which are used by the sections of a CMS_INPUT_CONTENTAREALISTinput 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 #index 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(#index)$ - at 6, 1

Therefore it is recommended, before using the system object #index , to check whether it is null or not:

$CMS_IF(!#index.isNull)$
...
$CMS_END_IF$

The system object: #index determines which number the currently rendered section has in the CMS_INPUT_CONTENTAREALIST input component or in other words: which section is rendered. The section counting begins with 0.

Important The system object: #index 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 #for.index :
$CMS_FOR(w, pt_cal)$
$CMS_VALUE(#for.index + 1)$/$CMS_VALUE(pt_cal.size)$: $CMS_VALUE(w)$
$CMS_END_FOR$

The return value of #index with data type: Integer

Examples of #index

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.

Important 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: 1st Section
2/3: 2nd Section
3/3: 3rd Section

© 2005 - 2014 e-Spirit AG | All rights reserved. | Last change: 2008-01-16