Use Smarty in your templates.
Install using composer:
composer require 'vierwd/symfony-smarty'
To use smarty templates for your controller just extend the Vierwd\Symfony\Smarty\Controller\SmartyController
.
You can then use $this->render('error/error.tpl')
to render a Smarty template.
// src/Controller/IndexController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Vierwd\Symfony\Smarty\Controller\SmartyController;
class IndexController extends SmartyController {
/**
* @Route("/", name="index")
*/
public function index(Request $request): Response {
return $this->render('index/index.tpl', ['message' => 'Hello from Smarty']);
}
}
{* templates/index/index.tpl *}
{$message}
There are some variables, that are always available to your templates:
Variable Name | Contents |
---|---|
app | Symfony\Bridge\Twig\AppVariable |
tagRenderer | Symfony\WebpackEncoreBundle\Asset\TagRenderer |
imageService | An image service which can be used to scale images using imagemagick |
authChecker | AuthorizationCheckerInterface |
- csrf_token
- integer
- url
- path
- svg
- twig
- widget
- inlineCSS
If you still need some twig logic, you can embed twig template code within your Smarty templates:
{$message}
{twig}
{literal}
{{ form_start(createForm) }}
{{ form_rest(createForm) }}
{/literal}
{/twig}