Gallery2:Themes:Reference:Modifiers - Gallery Codex
Personal tools

Gallery2:Themes:Reference:Modifiers

From Gallery Codex

Smarty Modifier Basics

Smarty uses modifiers to display text in different ways, for example to display as a string in capital letters, small letters, or title case. Any variable in a template can have a modifier applied to it by following it with a pipe symbol ('|') and the name of a modifier:

Using Modifiers

{$user.userName} Displays the variable $user.userName without any change in formatting
{$user.userName|upper} Displays the variable $user.userName in upper case letters using the upper modifier

Chaining Several Modifiers Together

Several modifiers can be chained together by separating each with a pipe symbol:

{$user.userName|upper|strip_tags} Displays the variable $user.userName applying the upper modifier first followed by the strip_tags modifier

Using Parameters with Modifiers

Certain modifiers can take parameters to control their behaviour, for example the built-in Smarty modifier truncate which truncates a string to a given length. The desired length of the string is passed as a parameter to the modifier:

{$user.userName|truncate:20} Displays the variable $user.userName truncated to 20 characters in length

If a modifier has several parameters, they must be passed in sequences, separated by colons. Optional parameters that you do not wish to specify a value for are given by omitting any value after its colon:

{$user.userName|truncate:20::true:true} Displays the variable $user.userName and passes four parameters to the truncate modifier:
  • Parameter 1 = 20 - the length to truncate at
  • Parameter 2 = optional and not specified
  • Parameter 3 = true
  • Parameter 4 = true

Further Information on Modifiers

Further information on using modifiers in templates, and the built-in modifiers in Smarty, can be found in the Smarty manual.

Gallery2 Smarty Modifiers

Gallery2 adds some extra modifiers to Smarty that help to format text for use in a gallery. These are:

entitytruncate

Usage: entitytruncate:length:etc:breakWords

The entitytruncate modifier truncates a string, but avoids making the truncation in the middle of an HTML entity or a multibyte character

Parameters:

  • length (integer)- maximum length for output string
  • etc (string) - a string to append to the end of a truncated string; the default is three full-stops ('...')
  • breakWords (boolean) - if true, entitytruncate will break a string in the middle of a word. The default is false

ireplace

Usage: ireplace:search:replace

ireplace performs a case insensitive search and replace on the variable it modifies, replacing search with replace

Parameters:

  • search (string) - a string to find in the variable
  • replace (string) - a string to replace search with

markup

Usage: markup

The markup modifier formats a variable according to the markup format set in the Site Admin settings (raw HTML, BBCode, or no formatting)

print_r

Usage: print_r

This modifier is used for debugging purposes and prints a variable recursively if it contains subkeys. More information on the print_r keyword is available in the PHP Manual

repeat

Usage: repeat:count

The repeat modifier repeats the variable a given number of times

Parameters:

  • count (integer) - the number of times to repeat the variable that this repeat is modifying

split

Usage: split:separator:regexp

split splits a variable into an array using the separator given. Further information on split is available in the PHP Manual

Parameters:

  • separator (string) - the string that marks the points where the variable should be split
  • regexp (boolean) - if true then separator is interpreted as a regular expression. The default is false