up

Variable modifiers

This is an advanced topic and can be ignored under normal circumstances.

Variable modifiers can be applied to variables. To apply a modifier, specify the value followed by a | (pipe) and the modifier name. A modifier may accept additional parameters that affect its behavior. These parameters follow the modifer name and are separated by a : (colon).

For example, if you have a datasource (recipients list) with the field surname and you want to make sure that the first letter of the surname is capitalized:

{$surname|capitalize}

This is a list of modifiers currently supported by SendCastle.
 

capitalize

Argument(s):
1. true/false (true for capitalizing all words)

Example: {$firstname|capitalize:true}
Result: Peter

cat (concatenate)

Argument(s):
n/a

Example: {$firstname|cat:$surname}
Result: Peter Andersson

count_characters

Argument(s):
1. true/false: This determines whether or not to include whitespace characters in the count.

Example: {$surname|count_characters}
Result: Number of characters in variable.

count_paragraphs

Argument(s):
n/a

Example: {$some_text_content|count_paragraphs}
Result: Number of paragraphs in variable.

count_sentences

Argument(s):
n/a

Example: {$some_text_content|count_sentences}
Result: Number of sentences in variable.

count_words

Argument(s):
n/a

Example: {$some_text_content|count_words}
Result: Number of words in variable.

date_format

Argument(s):
1. date format (see separate document)
2. default date

Example: {$currentdate|"%A, %B %e, %Y"}
Result: Monday, December 1, 2015

default

This is used to set a default value for a variable. If the variable is not set or empty, the given default value is printed instead. Default takes the one argument.

Argument(s):
1. the default value

Example: {$title|default:"Untitled"}
Result: Untitled

escape

Used to encode or escape a variable to for example html, url, single quotes, hex, hexentity, javascript and mail. By default its html.
 
Argument(s):
1. One of: html, htmlall, url, urlpathinfo, quotes, hex, hexentity, javascript, mail

Example:
Result:

indent

Argument(s):
1. Number of characters to indent
2. Character(s) to use as indentation

Example: {$title|indent:10:"."}
Result: ..........My Blog Entry

lower

This is used to lowercase a variable.

Argument(s):
n/a

Example: {$firstname|lower}
Result: peter

nl2br

All "\n" line breaks will be converted to html
tags in the given variable.

Argument(s):
n/a

Example: {$some_text_content|nl2br}
Result: The text content with
in it.

replace

Search and replace on a variable.

Argument(s):
1. This is the string of text to be replaced.
2. This is the string of text to replace with.

Example: {$country|replace:"Netherlands":"the Netherlands"}
Result: the Netherlands

spacify

Insert a space between every character of a variable. You can optionally pass a different character or string to insert.

Argument(s):
Character to insert

Example: {$firstname|spacify:"-"}
Result: P-e-t-e-r

string_format

This is a way to format strings, such as decimal numbers. Use the syntax of sprintf for the formatting.

Argument(s):
Format to use

Example: {$price|string_format:"%01.2f"}
Result: 123.20

strip

This replaces all repeated spaces, newlines and tabs with a single space, or with the supplied string.

Argument(s):
n/a

Example: {$firstname|strip}
Result: Peter

strip_tags

This strips out markup tags, basically anything between less-than and greater-than.

Argument(s):
1. true/false: This determines whether the tags are replaced by ' ' (space) (false) or '' (empty) (true)

Example: {$some_content|strip_tags}
Result: The content, but without HTML tags

truncate

This truncates a variable to a character length, the default is 80. As an optional second parameter, you can specify a string of text to display at the end if the variable was truncated. The characters in the string are included with the original truncation length. By default, truncate will attempt to cut off at a word boundary. If you want to cut off at the exact character length, pass the optional third parameter of TRUE.

Argument(s):
1. This determines how many characters to truncate to.
2. This is a text string that replaces the truncated text. Its length is included in the truncation length setting.
3. This determines whether or not to truncate at a word boundary with FALSE, or at the exact character with TRUE.
4. This determines whether the truncation happens at the end of the string with FALSE, or in the middle of the string with TRUE. Note that if this setting is TRUE, then word boundaries are ignored.


Example: {$articletext|truncate:200:" Read more...":true}
Result: 200 characters of the text ending with "Read more..."

upper

This is used to uppercase a variable.

Argument(s):
n/a

Example: {$firstname|upper}
Result: PETER

wordwrap

Wraps a string to a column width, the default is 80. As an optional second parameter, you can specify a string of text to wrap the text to the next line, the default is a carriage return "\n". By default, wordwrap will attempt to wrap at a word boundary. If you want to cut off at the exact character length, pass the optional third parameter as TRUE.

Argument(s):
1. This determines how many columns to wrap to.
2. This is the string used to wrap words with.
3. This determines whether or not to wrap at a word boundary (FALSE), or at the exact character (TRUE).

Example: {$some_text|wordwrap:40:"<br/>"}
Result: See description.