Start page / Template development / Template syntax / Functions / in the header / contentSelect

contentSelect

Contents
Output

The contentSelect function can be used to output datasets from the Content Store and can be used for further processing.

The function offers the opportunity to filter and/or sort datasets.

The result (return value) of the function is a list which contains all datasets matching the filter criteria. This list can be output for example using the instruction $CMS_FOR(...)$ (see section Output).

Syntax of the contentSelect function

The basic structure of the contentSelect function is as follows:

<CMS_FUNCTION name="contentSelect" resultname="IDENTIFIER">
<CMS_PARAM name="schema" value="IDENTIFIER" />
<CMS_VALUE_PARAM name="IDENTIFIER" value="VALUE" />
...
<QUERY entityType="IDENTIFIER">
<FILTERPARAM parameter="IDENTIFIER" datatype="DATATYPE" value="DEFAULT SELECTION" />
<FETCHMODE attribute="ATTRIBUTE" lazy="NUMERICAL_BOOLEAN_VALUE" />
<ORDERCRITERIA attribute="ATTRIBUTE" descending="NUMERICAL_BOOLEAN_VALUE" />
...
<EQ attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<NEQ attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<GT attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<GTE attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<LT attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<LTE attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<IS_NULL attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<NOTNULL attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<LIKE attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<AND>
<EQ attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
...
<LIKE attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<OR>
...
</OR>
...
</AND>
<OR>
<EQ attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
...
<LIKE attribute="ATTRIBUTE" parameter="IDENTIFIER" datatype="DATATYPE value="VALUE" />
<AND>
...
</AND>
...
</OR>
...
</QUERY>
</CMS_FUNCTION>
Important For common notes about the syntax of header functions please see introducing Functions page.

Parameters of the contentSelect function

The contentSelect function can be divided into a definition and a query part.

Definition part

Attribute

possible values

schema

constant

queryUid

constant

any parameter

expressions

  

You must specify schema or queryUid.

schema

The schema parameter is used to specify the database schema which is to be used for the query.

The value of the constant is the reference name of the database schema:

<CMS_FUNCTION name="contentSelect" resultname="name">
<CMS_PARAM name="schema" value="CONSTANT" />
...
</CMS_FUNCTION>

queryUid

As an alternative to the database schema specified via the schema parameter, you also can specify a query directly.

The reference name of the query is expected as the value of the parameter in this case.

Syntax:

<CMS_FUNCTION name="contentSelect" resultname="name">
<CMS_PARAM name="queryUid" value="KONSTANTE" />
</CMS_FUNCTION>

Example:

<CMS_FUNCTION name="contentSelect" resultname="myContentSelectFunction">
<CMS_PARAM name="queryUid" value="mySchema.myQuery"/>
</CMS_FUNCTION>

Note: If queryUid is used for the definition part, you don't need to define a query part by using <QUERY>.
If queryUid is used with

  • a <QUERY> tag or
  • <CMS_PARAM name="schema".../>

together, a save-preventing syntax error will occur.

Note: Only if the query is defined as a constant, an outgoing reference from the template to the query is created via the contentSelect function.

any parameter

By defining a freely selectable identifier, any number of expressions can be made available to the query as parameters.

The following characters may be used for the identifier:

A to Z, a to z, 0 to 9 and _.

Definition using expressions:

<CMS_FUNCTION name="contentSelect" resultname="name">
<CMS_VALUE_PARAM name="IDENTIFIER" value="EXPRESSION" />
...
</CMS_FUNCTION>

Example of the definition of the parameters from and to:

<CMS_FUNCTION name="contentSelect" resultname="name">
<CMS_VALUE_PARAM name="from" value="st_startDate" />
<CMS_VALUE_PARAM name="to" value="#global.now" />
...
</CMS_FUNCTION>

Note: st_startDate is a date input component (CMS_INPUT_DATE). #global.now is the starting point of the deployment.

See also page Database queries.

Query part

The query part of a contentSelect function is started with a QUERY tag. The QUERY tag is simultaneously the root element of the query.

All tags which are given between the opening and closing QUERY tag are taken into account in the query.

The entityType parameter is used to give the symbolic table name in the database schema so that the query can be applied to the datasets of the corresponding database table.

The limit parameter can be used for limiting the result of the query to a certain number of datasets.

Example:

<CMS_FUNCTION name="contentSelect" resultname="name">
<CMS_PARAM name="schema" value="CONSTANT" />
<QUERY entityType="IDENTIFIER" limit="10">
<.../>
</QUERY>
</CMS_FUNCTION>

QUERY tags

You can look up the tags which can be used with QUERY on the page Database queries:

Tip: Queries offer a wizard on the Conditions tab which assist you in creating queries using a graphical interface. The resulting source code can then be used as basis for the <QUERY/> part of the contentSelect function.

Output

The result of a contentSelect function can be output as follows:

$CMS_IF(!IDENTIFIER.isEmpty)$
$CMS_FOR(VARIABLE, IDENTIFIER)$
$CMS_VALUE(VARIABLE.fs_id)$: $CMS_VALUE(VARIABLE.COLUMNNAME)$
$CMS_END_FOR$
$CMS_END_IF$

In this example

  • IDENTIFIER is the identifier which is defined by the parameter resultname,
  • VARIABLE is the name of a variable and
  • COLUMNNAME is the name of a table column.

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.10 | Data privacy