VOLT: Template Engine

Volt provides Phalcon fast execution as it is very fast and designer friendly templating language written in C for PHP. It has many helpers defined to write views. Volt is inspired by Jinja and written by Armin Ronacher.

Implementation

Volt views are compiled in php which saves time to write php code manually.

Activating Volt

In this we register Volt in view component having extension .phtml.

Options available in volt

OptionDescriptionDefault
compiledPathA writable path where the compiled PHP templates will be placed./
compiledExtensionAn additional extension appended to the compiled PHP file.php
compiledSeparatorVolt replaces the directory separators / and \ by this separator in order to create a single file in the compiled directory%%
StatWhether Phalcon must check if exists differences between the template file and its compiled pathTrue
compileAlwaysTell Volt if the templates must be compiled in each request or only when they changeFalse
PrefixAllows to prepend a prefix to the templates in the compilation pathNull
autoescapeEnables globally autoescape of HTMLFalse

Variables

Object variables may have attributes which can be accessed using the syntax: foo.bar. If you are passing arrays, you have to use the square bracket syntax: foo['bar']

Filters

Variables can be formatted or modified using filters. The pipe operator (|) is used to apply filters to variables:

Following is the list of filters that can be used:

FilterDescription
absApplies the abs PHP function to a value.
CapitalizeCapitalizes a string by applying the ucwords PHP function to the value
convert_encodingConverts a string from one charset to another
DefaultSets a default value in case that the evaluated expression is empty (is not set or evaluates to a falsy value)
escapeApplies Phalcon\Escaper->escapeHtml() to the value
escape_attrApplies Phalcon\Escaper->escapeHtmlAttr() to the value
json_encodeConverts a value into its JSON representation
json_decodeConverts a value from its JSON representation to a PHP representation

Next TopicPhalcon Layer




Latest Courses