Инструменты пользователя

Инструменты сайта


limb3_2007_4:en:packages:macro:filters_intro

Filters. How to modify or format data on rendering.

Filters are used to modify or to apply some special formatting rule to variables in expressions. Filters are separated from other part of expression by vertical line. Several filters are separated by vertical lines too:

{$UserName|trim|capitalize}

In the example above, trim filter first removes spaces from begin and end of the $UserName variable and then capitalize filter converts first letter to uppercase. In the compiled php-file we will get something like this:

 <?php echo ucfirst(trim($UserName)); ?>

Filters parameters

Filters may also require additional information called parameters. The syntax for specifying parameters is:

{$UserName|default:"anonymous"}

If no value is specified by the application for the UserName property, then the value of «anonymous» is used. A parameter may be either a number constant, a string constant, or a variable.

Multiple parameters may be specified separated by commas:

{$value|number:2, '. ', ' '}

Here is an example of using of a variable as filter parameter:

<? $size = 10; ?>
<pre>{$PlainText|wordwrap:$size}</pre>

In most cases macro filters are just wrappers for php-function like trim, strtoupper, number_format etc. Default MACRO filters can be found in limb/macro/src/filter folder.

Обсуждение

Ваш комментарий. Вики-синтаксис разрешён:
  ____   _____   __  ___   __  ___ ______
 / __ \ / ___/  /  |/  /  /  |/  //_  __/
/ /_/ // /__   / /|_/ /  / /|_/ /  / /   
\___\_\\___/  /_/  /_/  /_/  /_/  /_/
 
limb3_2007_4/en/packages/macro/filters_intro.txt · Последние изменения: 2010/11/10 10:02 (внешнее изменение)