Table of Contents |
---|
Blesta 3.0 uses the H2o Template system for parsing Email Templates. The following is an overview of its basic usage. We've overridden the default {{ var_name }} with { var_name } for simplicity, but that's the only way in which the following documentation differ from any official H2o documentation.
Conditional Statements
{% if id > 3 %} This will print out if $id is > 3 {% endif %}
Loops
{% for user in users %} Name: {user.first_name} {user.last_name} {% endfor %}
Assuming:
$users = array( array( 'first_name'=>"First name", 'last_name'=>"Last name" ), array( 'first_name'=>"First name 2", 'last_name'=>"Last name 2" ) );
Loops can also take advantage of limits:
{% for user in users limit:1 %}
The above would only cycle through the loop one time.
Filters
Filters are applied to individual variables and are preceded by a pipe symbol (|). Parameters are passed to filters using a comma (,) separated list.
{past_due | set_default "Not past due"} // Produces "Not past due" if past_due is false
Multiple filters can be applied in succession:
{past_due | set_default "not past due" | capitalize} // Produces NOT PAST DUE if past_due is false
Supported Filters
Filter | Description | Example Usage |
---|---|---|
currency_format | Formats the value into a currency string. Parameters
| {"1.2345" | currency_format "USD"} |
md5 | Hashes the value using MD5. | {"some string" | md5} |
sha1 | Hahses the value using SHA1. | {"some string" | sha1} |
numberfromat | Formats the value into a number. Parameters
| {"12345.6789" | numberformat 2, ".", ","} |
wordwrap | Wraps a string into multiple lines. Parameters
| {"some string" | wordwrap 5, "\n<br />"} |
trim | Removes white space around a string. | {" some string " | trim} |
upper | Converts a string to uppercase. | {"some string" | upper} |
lower | Converts a string to lowercase. | {"SOME STRING" | lower} |
first | Returns the first element of an array. | {array_of_items | first} |
last | Returns the last element of an array. | {array_of_items | last} |
join | Combines an array of elements into a delimited string. Parameters
| {array_of_items | join ', '} |
length | Returns the length of an array. | {array_of_items | length} |
urlencode | URL encodes an string or array of parameters. | {array_of_items | urlencode} |
hyphenize | Replaces white space with hyphens. | {"some string" | hyphenize} |
urlize | Converts a URL into an HTML link. | {"http://domain.com/" | urlize} |
set_default | Sets a default value when no other value exists. Parameters
| {not_set | set_default "default value"} |
humanize | ||
capitalize | ||
capfirst | ||
tighten_space | ||
escape | ||
escapejson | ||
force_escape | ||
truncate | ||
limitwords | ||
filesize | ||
image_tag | ||
css_tag | ||
script_tag | ||
links_to | ||
links_with | ||
strip_tags | ||
linebreaks | ||
nl2br | ||
nl2pbr | ||
htmlAttribute | ||
extract | ||
date | ||
relative_time | ||
relative_date | ||
relative_datetime |
Debugging
Adding the following tag to any email template will enable debugging, and display data key value pairs:
{% debug %}