Online Chat
 Call Us: 
1-877-744-1221
Browse Submit a Ticket
 
Advanced Search
Tools
Rss Categories

Modifiers

Author: Eileen Wilde Reference Number: AA-00168 Views: 15884 Last Updated: 04/06/2010 06:15 AM 0 Rating/ Voters

Modifiers

  1. Modifiers overview
  2. Modifiers Reference
    1. capitalize
    2. count_characters
    3. count_paragraphs
    4. count_sentences
    5. count_words
    6. csv_shielding
    7. date_format
    8. default
    9. floorval
    10. indent
    11. lower
    12. nl2br
    13. regex_replace
    14. replace
    15. roundval
    16. spacify
    17. string_format
    18. strip
    19. strip_tags
    20. truncate
    21. upper
    22. wordwrap
  3. 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:

{#title|upper#}
{#title|truncate:40:"..."#}
{#title|lower#}

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:

Input:john smith

Template:

{#name|capitalize#}

Output:

John Smith

count_characters

This is used to count the number of characters in a variable.

Example:

Input:

john smith

Template:

{#name|count_characters#}

Output:

9

count_paragraphs

This is used to count the number of paragraphs in a variable.

Example:

Input:

This is a test paragraph.
The next paragraph

Template:

{#article|count_paragraphs#}

Output:

2

count_sentences

This is used to count the number of sentences in a variable.

Example:

Input:

His name is John Smith. He is a good man.

Template:

{#ext|count_sentences#}

Output:

2

count_words

This is used to count the number of words in a variable.

Example:

Input:

His name is John Smith. He is a good man.

Template:

{#text|count_words#}

Output:

10

csv_shielding

This is used to shield double quotes when using CSV file.

Example:

Input:

His name is "John Smith". He is a good man.

Template:

"{#text|csv_shielding#}"

Output in file:

"His name is ""John Smith"". He is a good man."

Output in Excel:

His name is "John Smith". He is a good man.

date_format

Returns a string formatted according to the given format string. Use variable %TIMESTAMP to get a timestamp

Example:

Template:

{#%TIMESTAMP|date_format:"m/d/y"#}

Output:

12/15/2006

You can also use characters from following tables to customize the "date_format" modifier.

The following characters are recognized in the date_format modifier
dDay of the month, 2 digits with leading zeros (01 to 31)
DA three letter textual representation for a day (Mon through Sun)
jDay 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)
NISO-8601 numeric representation of the day of the week (1 - for Monday - through 7 - for Sunday)
SEnglish two characters ordinal suffix for the day of the month (st, nd, rd or th. Works well with "j")
wNumeric representation of the day of the week (0  - for Sunday - through 6 - for Saturday)
zThe day of the year (0 through 365)
WISO-8601 week number of the year with weeks starting on Monday (Example: 42 - the 42nd week in the year)
FA full textual representation of a month, such as January or March (January through December)
mNumeric representation of a month, with leading zeros (01 through 12)
MA short three letter textual representation of a month (Jan through Dec)
nNumeric representation of a month, without leading zeros (1 through 12)
tNumber of days in the given month (28 through 31)
LWhether it's a leap year (1 if it is a leap year, 0 otherwise.)
oISO-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)
YA full four digit numeric representation of a year (Examples: 1999 or 2003)
yA two digit representation of a year (Examples: 99 or 03)
aLowercase Ante Meridiem and Post Meridiem (am or pm)
AUppercase Ante Meridiem and Post Meridiem (AM or PM)
BSwatch Internet time (000 through 999)
g12-hour format for an hour without leading zeros (1 through 12)
G24-hour format for an hour without leading zeros (0 through 23)
h12-hour format for an hour with leading zeros (01 through 12)
H24-hour format for an hour with leading zeros (00 through 23)
iMinutes, with leading zeros (00 to 59)
sSeconds, with leading zeros (00 through 59)
uMicroseconds (Example: 54321)
eTimezone 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.)
ODifference from Greenwich Meridian Time (GMT) in hours (Example: +0200)
PDifference Greenwich Meridian Time (GMT) with a colon between hours and minutes (Example: +02:00)
TTime zone abbreviation (Examples: EST, MDT ...)
ZTime 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)
Note:
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:

Input:

Template:

{#name|default:"-=none=-"#}

Output:

-=none=-

floorval

Deletes decimal part of digit

Example:

Input:

123.834

Template:

{#name|floorval#}

Output:

123

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:

Input:

NJ judge to rule on nude beach.
Sun or rain expected today, dark tonight.
Statistics show that teen pregnancy drops off significantly after 25.   

Template:

{#article|indent:10#}

Output:

NJ judge to rule on nude beach.
Sun or rain expected today, dark tonight.
Statistics show that teen pregnancy drops off significantly after 25.

lower

This is used to change a variable to lowercase.

Example:

Input:

John SMITH   

Template:

{#name|lower#}

Output:

john smith

nl2br

All line breaks will be converted to <br> tags in the given variable. It's very useful to output text area fields

Example:

Input:

John

Smith

Template:

{#name|nl2br#}

Output:

John<br>Smith

regex_replace

A regular expression search and replace on a variable. Use the syntax for preg_replace() from the PHP manual.

Example:

Input:

John Smith   

Template:

{#name|regex_replace:"/h/":"H"#}

Output:

JoHn SmitH

replace

A simple search and replace on a variable.

Example:

Input:

John Smith   

Template:

{#name|replace:"John":"Samuel"#}

Output:

Samuel Smith

roundval

Rounds a digit

Example:

Input:

123.834

Template:

{#name|roundval#}

Output:

124

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:

Input:

John

Template:

{#name|spacify#}

Output:

J o h n

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:

Input:

2.43243252

Template:

{#num|string_format:"%.2f"#}

Output:

2.43

strip

This replaces all repeated spaces, new lines, and tabs with a single space, or with a supplied string

Example:

Input:

John                  Smith

Template:

{#name|strip#}

Output:

John Smith

strip_tags

This strips out markup tags, basically anything between < and >.

Example:

Input:

John <b>Smith</b>

Template:

{#name|strip_tags#}

Output:

John Smith

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:

Input:

Two Sisters Reunite after Eighteen Years at Checkout Counter

Template:

{#article|truncate:30:"...":true#}

Output:

Two Sisters Reunite after E...

upper

This is used to change a variable to uppercase.

Example:

Input:

John Smith

Template:

{#name|upper#}

Output:

JOHN SMITH

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:

Input:

Blind woman gets new kidney from dad she hasn't seen in years.

Template:

{#article|wordwrap:"30":"\n":"true"#}

Output:

Blind woman gets new kidney

from dad she hasn't seen in

years.

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:

Input:

Smokers are Productive, but Death Cuts Efficiency

Template:

{#article#}
{#article|upper|spacify#}
{#article|lower|spacify|truncate#}
{#article|lower|truncate:30|spacify#}
{#article|lower|spacify|truncate:30:"..."#}

Output:

Smokers are Productive, but Death Cuts Efficiency.
S M O K E R S   A R E   P R O D U C T I V E ,   B U T   D E A T H   C U T S   E F F I C I E N C Y .
s m o k e r s   a r e   p r o d u c t i v e ,   b u t   d e a t h   c u t s...
s m o k e r s   a r e   p r o d u c t i v e ,   b u t ...
s m o k e r s   a r e   p...