talira

PHP template engine with context-sensitive escaping

open sourceBSD-3-Clause OR GPL-2.0-only OR GPL-3.0-onlyfree

Latte is a templating engine for PHP from the Nette project, usable on its own or in Nette Framework. Its expressions are written as in PHP, with one {...} delimiter, and it understands the HTML around them, so it escapes each variable for its context (text, attributes, unquoted attributes or JavaScript) to stop cross-site scripting. Paired tags can be written as n:attributes on an HTML element, templates use layouts and inheritance, and a sandbox mode limits the tags, filters and functions templates from untrusted authors can use. Templates compile to plain PHP and recompile when the source changes, and a Tracy panel shows which templates and variables a page rendered. Install it from Packagist as latte/latte.

Problems it solves

  • a PHP template engine that escapes output correctly in attributes and scripts
  • let users edit page templates in my PHP app without giving them full PHP
  • write PHP templates without learning a new syntax like Twig's

Features

  • context-sensitive escaping against XSS
  • PHP expression syntax with one delimiter
  • n:attributes for paired tags
  • layouts and template inheritance
  • sandbox mode for untrusted templates
  • compiles to plain PHP
  • Tracy debugger panel
  • PhpStorm and NetBeans support

Alternatives

The same job

These do what Latte does.

  1. Twig The flexible, fast, and secure template engine for PHP
  2. Smarty (PHP) The compiling template engine for PHP

Compare Latte with the top 3