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

#index

The system object #index is available in templates which are used by the elements of an

In other words: if an element in one of these input component types is rendered the system object is available in the referenced section or link template.

If #index is used in a template and this is rendered outside of FS_CATALOG the return is null. This will be displayed in the preview/generation log. 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 element has in the FS_CATALOG input component or in other words: which element is rendered. Counting begins with 0.

Important The system object #index is not available for the output of an FS_CATALOG 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(section, pt_sectionlist)$
$CMS_VALUE(#for.index + 1)$/$CMS_VALUE(pt_sectionlist.size)$: $CMS_VALUE(section)$
$CMS_END_FOR$

The return value of #index is 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 sections

Definition of the FS_CATALOG input component (form):

<CMS_MODULE>
<FS_CATALOG name="st_catalog">
<LANGINFOS>
<LANGINFO lang="*" label="Section list"/>
</LANGINFOS>
<TEMPLATES type="section">
<TEMPLATE uid="text"/>
</TEMPLATES>
</FS_CATALOG>
</CMS_MODULE>

Invocation of the input component (HTML template set):

$CMS_VALUE(st_catalog)$

Definition of the section template (“text”, 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 template set):

<CMS_HEADER />
$CMS_IF(!#index.isNull && !#fs_catalog.size.isNull)$
$CMS_VALUE(#index + 1)$/$CMS_VALUE(#fs_catalog.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 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.4 | Data privacy