symfony/templating

Provides all the tools needed to build any kind of template system

Installs: 53 510 791

Dependents: 650

Suggesters: 58

Security: 0

Stars: 1 027

Watchers: 5

Forks: 15

v6.4.8 2024-05-31 14:49 UTC

This package is auto-updated.

Last update: 2024-09-25 14:26:07 UTC


README

The Templating component provides all the tools needed to build any kind of template system.

It provides an infrastructure to load template files and optionally monitor them for changes. It also provides a concrete template engine implementation using PHP with additional tools for escaping and separating templates into blocks and layouts.

Getting Started

$ composer require symfony/templating
use Symfony\Component\Templating\Loader\FilesystemLoader;
use Symfony\Component\Templating\PhpEngine;
use Symfony\Component\Templating\Helper\SlotsHelper;
use Symfony\Component\Templating\TemplateNameParser;

$filesystemLoader = new FilesystemLoader(__DIR__.'/views/%name%');

$templating = new PhpEngine(new TemplateNameParser(), $filesystemLoader);
$templating->set(new SlotsHelper());

echo $templating->render('hello.php', ['firstname' => 'Fabien']);

// hello.php
Hello, <?= $view->escape($firstname) ?>!

Resources