Twig

2011.12.04 Symfony   #5
       @fivestr
ABOUT ME

    @fivestr



      PHP
Twig

Twig

       TIPS
Twig
Twig



{{ foo }} => <?php echo $foo ?>
{% if %}...{% endif %}
Twig

{{ foo(arg) }} :

{{ arg|foo }} :

{% if arg is foo %} :

{% foo %}{% endfoo %} :
Twig




Twig_Extension
DemoExtension


src/Acme/DemoBundle/Twig/Extension/
DemoExtension.php
code
class DemoExtension extends Twig_Extension
{
   public function getFunctions()
   {
     return array(
        'code' => new Twig_Function_Method(
           $this, 'getCode',
           array('is_safe' => array('html'))
        ),
     );
   }
}
getFunctions()

                 getFunctions()


     Twig
Twig_Function_Method(
  $this, ‘getCode’, $options)
public function getCode($template) {}
{{ code(template) }}
 $this->getCode($template)
getFilters() / getTests()
Twig_Filter_Method / Twig_Filter_Test
DI

 twig.extension
Twigエクステンションの作り方
Twigエクステンションの作り方

Twigエクステンションの作り方