Escaping Values
The "escape" modifier encodes or escapes values. The first argument indicates the type of escaping to perform, with "html" as the default. The options are:
- html
- Turns & " ' < > into entity equivalents.
- htmlall
- Turns all HTML tags into entity equivalents.
- url
- Makes the value safe to pass in a URL (like PHP's urlencode() function).
- quotes
- Escapes quotes by preceding them with the backslash.
- hex
- Turns characters into their hex equivalent.
- hexentity
- Turns characters into their hex entity equivalent. (see the image at right)
- javascript
- Uses JavaScript to help hide how the value looks in the HTML source code.
- mail
- Turns 'something@example.com' into 'something [AT] example [DOT] com'
For protecting e-mail addresses, also see Obfuscating E-mail Addresses.
The "strip_tags" modifier removes all HTML tags entirely.
Adjusting Spacing
The "indent" modifier indents lines 4 spaces (you can change this default indent). The "nl2br" modifier converts newline characters to HTML break tags.
The "spacify" modifier inserts a space between every character in a value. Its one parameter allows you to change what character (or sequence of characters) is inserted.
The "strip" modifier removes repeated spacing characters (spaces, newlines, and tabs) with a single space.
The "word_wrap" modifier wraps a string to a set length. It's equivalent to PHP's wordwrap() function.
Replacing Values using Smarty Replace Modifier
The "replace" modifier performs a simple string replacement on a value, like PHP's str_replace() function. The following replaces uses of 'foo' with 'bar':
{$var|replace:'foo':'bar'}
The "regex_replace" modifier allows you to apply Perl-compatible regular expressions to values. It's equivalent to PHP's preg_replace() function.
Formatting Strings
The "string_format" modifier is the equivalent of PHP's sprintf() function, used to format a string. The "truncate" modifier truncates a string to a length. By default, this modifier truncates a string to approximately 80 characters, ending at a word, and adds an ellipsis (...) to the value. "truncate" is an obvious tool for putting a preview of a longer bit of text on a page.
Modifying Arrays
The @ symbol applies a modifier to an entire array, rather than to each element in the array.
{$some_array|@lower}
|