Modifiers
- Modifiers overview
- Modifiers Reference
- capitalize
- count_characters
- count_paragraphs
- count_sentences
- count_words
- csv_shielding
- date_format
- default
- floorval
- indent
- lower
- nl2br
- regex_replace
- replace
- roundval
- spacify
- string_format
- strip
- strip_tags
- truncate
- upper
- wordwrap
- Combining modifiers
Modifiers overview
Modifiers used to perform certain transformations with user input prior to inserting results into a template or generating output.
Variable modifiers can be applied to any variable in a template tag. To apply a modifier, specify the value followed by the | (pipe) and the modifier name. A modifier may accept additional parameters that affect its behaviour. These parameters follow the modifier name and are separated by colons (:) and surrounded by double-quotes.
Examples:
The first example makes the value of the title variable all uppercase. The second truncates the value to 40 characters and add (…) at the end of the string and the third makes the value of the title variable all lowercased.
Modifiers Reference
capitalize
This is used to capitalize the first letter of all words in a variable.
Example:
count_characters
This is used to count the number of characters in a variable.
Example:
count_paragraphs
This is used to count the number of paragraphs in a variable.
Example:
count_sentences
This is used to count the number of sentences in a variable.
Example:
count_words
This is used to count the number of words in a variable.
Example:
csv_shielding
This is used to shield double quotes when using CSV file.
Example:
date_format
Returns a string formatted according to the given format string. Use variable %TIMESTAMP to get a timestamp
Example:
You can also use characters from following tables to customize the "date_format" modifier.
d | Day of the month, 2 digits with leading zeros (01 to 31) |
D | A three letter textual representation for a day (Mon through Sun) |
j | Day of the month (number) without leading zeros (1 to 31) |
l (lowercase 'L') | A full textual representation of the day of the week (Sunday through Saturday) |
N | ISO-8601 numeric representation of the day of the week (1 - for Monday - through 7 - for Sunday) |
S | English two characters ordinal suffix for the day of the month (st, nd, rd or th. Works well with "j") |
w | Numeric representation of the day of the week (0 - for Sunday - through 6 - for Saturday) |
z | The day of the year (0 through 365) |
W | ISO-8601 week number of the year with weeks starting on Monday (Example: 42 - the 42nd week in the year) |
F | A full textual representation of a month, such as January or March (January through December) |
m | Numeric representation of a month, with leading zeros (01 through 12) |
M | A short three letter textual representation of a month (Jan through Dec) |
n | Numeric representation of a month, without leading zeros (1 through 12) |
t | Number of days in the given month (28 through 31) |
L | Whether it's a leap year (1 if it is a leap year, 0 otherwise.) |
o | ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (Examples: 1999 or 2003) |
Y | A full four digit numeric representation of a year (Examples: 1999 or 2003) |
y | A two digit representation of a year (Examples: 99 or 03) |
a | Lowercase Ante Meridiem and Post Meridiem (am or pm) |
A | Uppercase Ante Meridiem and Post Meridiem (AM or PM) |
B | Swatch Internet time (000 through 999) |
g | 12-hour format for an hour without leading zeros (1 through 12) |
G | 24-hour format for an hour without leading zeros (0 through 23) |
h | 12-hour format for an hour with leading zeros (01 through 12) |
H | 24-hour format for an hour with leading zeros (00 through 23) |
i | Minutes, with leading zeros (00 to 59) |
s | Seconds, with leading zeros (00 through 59) |
u | Microseconds (Example: 54321) |
e | Timezone identifier (Examples: UTC, GMT, Atlantic/Azores) |
I (capital i) | Whether or not the date is in daylight savings time (1 if Daylight Saving Time, 0 otherwise.) |
O | Difference from Greenwich Meridian Time (GMT) in hours (Example: +0200) |
P | Difference Greenwich Meridian Time (GMT) with a colon between hours and minutes (Example: +02:00) |
T | Time zone abbreviation (Examples: EST, MDT ...) |
Z | Time zone offset in seconds. The offset for time zones west of UTC is always negative, and for those east of UTC is always positive. (-43200 through 50400) |
Unrecognized characters in the format string will be printed as-is.
default
This is used to set a default value for a variable. If the variable is empty, the given default value is printed instead. Default takes one argument.
Example:
floorval
Deletes decimal part of digit
Example:
indent
This indents a string at each line (the default is 4). As an optional parameter, you can specify the number of characters to indent. As an optional second parameter, you can specify the character to use to indent with. (Use "\t" for tabs.)
Example:
lower
This is used to change a variable to lowercase.
Example:
nl2br
All line breaks will be converted to <br> tags in the given variable. It's very useful to output text area fields
Example:
regex_replace
A regular expression search and replace on a variable. Use the syntax for preg_replace() from the PHP manual.
Example:
replace
A simple search and replace on a variable.
Example:
roundval
Rounds a digit
Example:
spacify
Spacify is a way to insert a space between every character of a variable. You can optionally pass a different character (or string) to insert.
Example:
string_format
This is a way to format strings, such as decimal numbers. Use the syntax for the sprintf PHP function for the formatting.
Example:
strip
This replaces all repeated spaces, new lines, and tabs with a single space, or with a supplied string
Example:
strip_tags
This strips out markup tags, basically anything between < and >.
Example:
truncate
This truncates a variable to a character length (default is 80). As an optional second parameter, you can specify a string of text to display at the end of the string 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.
Example:
upper
This is used to change a variable to uppercase.
Example:
wordwrap
This wraps a string to a column width (default is 80). As an optional second parameter, you can specify a string of text to wrap the text to the next line (default is 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 of true.
Example:
Combining modifiers
You can apply any number of modifiers to a variable. They will be applied in the order they are combined, from left to right. They must be separated with a | (pipe) character.
Example: