TemplateEngineLatte by daun

Latte templates for the TemplateEngineFactory

Build Status StyleCI License: MIT ProcessWire 3

A ProcessWire module adding Latte to the TemplateEngineFactory.

  • ProcessWire 3.0 or newer
  • TemplateEngineFactory 2.0 or newer
  • PHP 7.1 or newer
  • Composer

Execute the following command in the root directory of your ProcessWire installation:

composer require daun/template-engine-latte:^1.0

This will install the TemplateEngineLatte and TemplateEngineFactory modules in one step. Afterwards, don't forget to enable Latte as engine in the TemplateEngineFactory module's configuration.

ℹ️ This module includes test dependencies. If you are installing on production with composer install, make sure to pass the --no-dev flag to omit autoloading any unnecessary test dependencies!.

The module offers the following configuration:

  • Template files suffix The suffix of the Latte template files, defaults to latte.
  • Default layout file Layout that all views will extend from unless overwritten.
  • Provide ProcessWire API variables in Latte templates API variables ($pages, $input, $config...) are accessible in Latte, e.g. {$config} for the config API variable.
  • Simplified path resolution Enable Blade-style dot syntax for directory traversal. See below.
  • Auto refresh templates (recompile) Recompile templates whenever the source code changes.

This option will enable two things:

  • Allow dot syntax for directory traversal à la Blade.
  • Prepend the base view directory to all paths, eliminating the need for endless ../ in subdirectories.

Both of these will resolve to site/templates/views/partials/navigation.latte:

  • Normal resolution: {include '../../partials/navigation.latte'}
  • Simplified resolution enabled: {include 'partials.navigation'}

It is possible to extend Latte after it has been initialized by the module. Hook the method TemplateEngineLatte::initLatte to register custom macros, filters, functions etc.

Here is an example how you can use the provided hook to add custom macros and filters.

wire()->addHookAfter('TemplateEngineLatte::initLatte', function (HookEvent $event) {
    /** @var Latte\Engine */
    $latte = $event->arguments('latte');
    $compiler = $latte->getCompiler();

    // Add filter
    $latte->addFilter('lower', function ($str) { return strtolower($str); });

    // Add macro
        'if (get_class(%node.word) === "ProcessWire\Page" && %node.word->id) {',

The above hook can be put in your site/init.php file. If you prefer to use modules, put it into the module's init() method and make sure that the module is auto loaded.

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Latest news

  • ProcessWire Weekly #489
    In the 489th issue of ProcessWire Weekly we'll check out what's new in the core this week, share a brand-new recipe of the week, and more. Read on!
    Weekly.pw / 23 September 2023
  • ProcessWire 3.0.226 new main/master version
    After 8 months in development we are excited to bring you ProcessWire 3.0.226 main/master. This version has a ton of great new features, improvements and optimizations, plus more than 100 issue fixes. This post takes an in-depth look at highlights from this great new version.
    Blog / 25 August 2023
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK