Start page / Template development / Template syntax / Instructions / $CMS_TRIM

$CMS_TRIM(...)$Available from FirstSpirit Version 2.3

Using $CMS_TRIM(...)$

The instruction $CMS_TRIM(...)$ is used to format the generated source text of a page or of a section.

The instruction can be used to remove unnecessary empty rows and whitespaces (carriage return, line feed, tab and space) from the generated source text.

Removing these unnecessary characters makes the generated pages smaller. It is therefore advisable to use the $CMS_TRIM(...)$ instruction in all projects.

For the parameter level a value larger or equal to 2 should be selected.

Syntax of $CMS_TRIM(...)$

The syntax of the $CMS_TRIM(...)$ instruction is as follows:

$CMS_TRIM(level:LEVEL, char:CHAR)$
CONTENT
$CMS_END_TRIM$

Within a $CMS_TRIM(...)$ statement multiple parameters are passed comma separated.

For LEVEL and CHAR expressions can be given; however, for better legibility it is advisable to use constants .

Example where constants are specified:

$CMS_TRIM(level:3, char:"\r\n")$
...
$CMS_END_TRIM$

Parameters of $CMS_TRIM(...)$

$CMS_TRIM(...)$ has the following parameters:

  • level
  • char

Important The level parameter is a mandatory parameter.

Setting to remove whitespaces (level)

The level parameter is used to specify which whitespaces are to be removed with the help of $CMS_TRIM(...)$.

The parameter expects an integer value.

level

Meaning

0

No change to the whitespaces.

1

All consecutive rows of the source text which only contain whitespaces are grouped together to form a single row .

2

All rows of the source text which only contain whitespaces are removed.

3

Analogous to 2 all rows of the source text which contain whitespaces only are removed.

In addition, with this setting the leading and trailing whitespaces in each row are also removed.

4

All consecutive whitespaces are grouped together to form one space.

Leading and trailing spaces are also removed.

  
Important When specifying a level 4 Java scripts do not work as the necessary line breaks are removed!

Definition of a character string to exit the end rows (char)

The char parameter is used to define the character string with which a "trimmed" row of the generated source text is to be ended.

The character string given here is therefore set at the end of all rows edited using the instruction $CMS_TRIM(...)$.

As a default, rows are ended with the character string "\n" (line break) if $CMS_TRIM(...)$ is used.

The following syntax must be adhered to when using $CMS_TRIM(...)$:

$CMS_TRIM(level:INTEGER,char:"CHARACTER")$
...
$CMS_END_TRIM$

or

$CMS_TRIM(level:LEVEL, char:CHAR)$
...
$CMS_END_TRIM$

A Linking of char and level can be given as follows:

$CMS_TRIM(level:3,char:"\n")$
...
$CMS_END_TRIM$

In the code example the parameter level is used in level 3 , i.e. all characters of the source text which contain whitespaces only are removed and in addition leading and trailing whitespaces are removed from each row.

All rows which are not completely removed but in which whitespaces only were removed are now ended by the character string "\n".

Examples of $CMS_TRIM(...)$

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: level 0

Code example:

$CMS_TRIM(level:0)$·◄


<!--Here·is·a·comment-->
···Here·is·a·text·◄
·$CMS_END_TRIM$

Description:

The content between $CMS_TRIM(...)$ and $CMS_END_TRIM$ is subjected to the replacements of level 0 .

Output:

·◄


<!--Here·is·a·comment-->
···Here·is·a·text·◄
·

(Display: Spaces = · and line break = )

2nd Example: level 1

Code example:

$CMS_TRIM(level:1)$·◄


<!--Here·is·a·comment-->
···Here·is·a·text·◄
·$CMS_END_TRIM$

Description:

The content between $CMS_TRIM(...)$ and $CMS_END_TRIM$ is subjected to the replacements of level 1 .

Output:


<!--Here·is·a·comment-->
···Here·is·a·text·◄

(Display: Spaces = · and line break = )

3rd Example: level 2

Code example:

$CMS_TRIM(level:2)$·◄


<!--Here·is·a·comment-->
···Here·is·a·text·◄
·$CMS_END_TRIM$

Description:

The content between $CMS_TRIM(...)$ and $CMS_END_TRIM$ is subjected to the replacements of level 2 .

Output:

<!--Here·is·a·comment-->
···Here·is·a·text·◄

(Display: Spaces = · and line break = )

4th Example: level 3

Code example:

$CMS_TRIM(level:3)$·◄


<!--Here·is·a·comment-->
···Here·is·a·text·◄
·$CMS_END_TRIM$

Description:

The content between $CMS_TRIM(...)$ and $CMS_END_TRIM$ is subjected to the replacements of level 3 .

Output:

<!--Here·is·a·comment-->
Here·is·a·text

(Display: Spaces = · and line break = )

5th Example: level 4

Code example:

$CMS_TRIM(level:4)$·◄


<!--Here·is·a·comment-->
···Here·is·a·text·◄
·$CMS_END_TRIM$

Description:

The content between $CMS_TRIM(...)$ and $CMS_END_TRIM$ is subjected to the replacements of level 4 .

Output:

<!--Here·is·a·comment--> Here·is·a·text

(Display: Spaces = · and line break = )

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