Skip to content

Commit

Permalink
Fix Twig namespaces and update doc for twig runtime extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Phenix789 authored and javiereguiluz committed Jul 3, 2018
1 parent b569015 commit de8b1e7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions components/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Bridge\Twig\Form\TwigRenderer;
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Twig\RuntimeLoader\FactoryRuntimeLoader;

// the Twig file that holds all the default markup for rendering forms
// this file comes with TwigBridge
Expand All @@ -194,7 +197,7 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
// the path to your other templates
$viewsDirectory = realpath(__DIR__.'/../views');

$twig = new Twig_Environment(new Twig_Loader_Filesystem(array(
$twig = new Environment(new FilesystemLoader(array(
$viewsDirectory,
$vendorTwigBridgeDirectory.'/Resources/views/Form',
)));
Expand Down Expand Up @@ -251,7 +254,7 @@ installed:
$ composer require symfony/translation symfony/config
Next, add the :class:`Symfony\\Bridge\\Twig\\Extension\\TranslationExtension`
to your ``Twig_Environment`` instance::
to your ``Twig\\Environment`` instance::

use Symfony\Component\Form\Forms;
use Symfony\Component\Translation\Translator;
Expand Down
2 changes: 1 addition & 1 deletion reference/configuration/twig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ called to determine the default escaping applied to the template.
base_template_class
~~~~~~~~~~~~~~~~~~~

**type**: ``string`` **default**: ``'Twig_Template'``
**type**: ``string`` **default**: ``'Twig\\Template'``

Twig templates are compiled into PHP classes before using them to render
contents. This option defines the base class from which all the template classes
Expand Down
7 changes: 5 additions & 2 deletions templating/twig_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ As an example you'll create a price filter to format a given number into price::
// src/AppBundle/Twig/AppExtension.php
namespace AppBundle\Twig;

class AppExtension extends \Twig_Extension
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class AppExtension extends AbstractExtension
{
public function getFilters()
{
return array(
new \Twig_SimpleFilter('price', array($this, 'priceFilter')),
new TwigFilter('price', array($this, 'priceFilter')),
);
}

Expand Down

0 comments on commit de8b1e7

Please sign in to comment.