Parser package

The Parser package extends the Core View class to be able to use any type of template parser you want.


The Parser package changes nothing about the way you work with Views, but it will allow you to use any template parser you want instead of PHP. The package comes with many drivers for parsers like Mustache, Markdown, Twig and Smarty.

Which parser is used is chosen by the file extension of your view file. Normal views are extended .php and will use PHP to parse the template, for these the .php extension may also be omitted. All others have their own specific extension, for example foo.mustache will use the Mustache driver and foo.tpl will use the Dwoo driver (expected extensions can be changed in config).


The Parser package is included in the Fuel download. To use it you must first enable it by adding it to your config:

'always_load' => array(
	'packages' => array(

While many drivers are included, most of the libraries are not. Only Mustache and Markdown are included in the vendor directory of the package and work out of the box.

Mustache, Twig, MtHaml and Smarty should be installed via Composer. Simply add the libraries to your project's composer.json then run "php composer.phar install":

    "require": {
        "mustache/mustache" : "*",
        "smarty/smarty" : "*",
        "twig/twig" : "*",
        "mthaml/mthaml": "*"


Parser can be configured in a config/parser.php file and takes the following keys:

Param Type Default Description
extensions array (array with extensions and View class which parses them) Defines which extensions are valid and what their View driver is.

Runtime Configuration

All drivers have a parser() method that will allow you to access the current Parser object. This is a convention and not a requirement and might be different on 3rd party drivers.

// Clear the cache for a specific Smarty template
$view = View::forge('example.smarty');

// Example static usage