vierwd/symfony-smarty

Symfony Smarty Component

dev-main 2022-02-01 16:34 UTC

This package is auto-updated.

Last update: 2024-11-29 06:10:24 UTC


README

Use Smarty in your templates.

Installation

Install using composer:

composer require 'vierwd/symfony-smarty'

Usage in controllers

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.

Example

// 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}

Pre-defined variables

There are some variables, that are always available to your templates:

Pre-defined smarty functions, blocks and modifiers

  • csrf_token
  • integer
  • url
  • path
  • svg
  • twig
  • widget
  • inlineCSS

Power-Block: twig

If you still need some twig logic, you can embed twig template code within your Smarty templates:

Twig in Smarty template

{$message}
{twig}
	{literal}
		{{ form_start(createForm) }}
		{{ form_rest(createForm) }}
	{/literal}
{/twig}