ViewFish PHP Templating Engine

Functions

You can manipulate variables using piped functions: {{variable|function}}. Functions can be chained, meaning {{variable|function1|function2|function3}} is valid syntax — each function receives the output of the previous one.

Default Functions

These are available out of the box:

Function Description
trim Remove leading/trailing whitespace
ucfirst Capitalize the first letter
ucwords Capitalize the first letter of each word
nl2br Convert newlines to <br> tags
strtoupper Convert to uppercase
strtolower Convert to lowercase
htmlspecialchars Encode HTML entities
number_format Format number with thousands separator
stripslashes Remove backslashes
strip_tags Remove HTML tags
md5 Generate MD5 hash
intval Convert to integer

Shorthand Aliases

Alias Equivalent
upper strtoupper
lower strtolower
escape htmlspecialchars (with ENT_QUOTES, UTF-8)
e Same as escape
sup Wrap output in <sup> tags
sub Wrap output in <sub> tags

Multi-Argument Functions

Some functions accept arguments in the format {{var|function:arg1:arg2}}:

Function Syntax Example
substr substr:offset:length {{str|substr:0:10}}
ellipsis ellipsis:max_length {{title|ellipsis:25}}
date date:format {{created|date:M j, Y}}
default default:"fallback" {{name|default:"Anonymous"}}

ellipsis trims a string and appends "…" only if it exceeds the specified length.

date formats a date string using PHP's date() format characters. The input value should be a parseable date string.

default provides a fallback value when the variable is empty or missing. See the Default Values page for details.

Chaining Examples

{{name|trim|ucwords}}
{{email|lower|escape}}
{{bio|ellipsis:100|nl2br}}
{{city|default:"Unknown"|ucwords}}