Thanks Fabien.

Indeed I was doing well :
 - creating a FooExtension class extending TwigExtension
 - defining some custom filters or functions in it
 - registering that class as a service with a twig.extension tag name

But custom functions weren't found by twig, 2 reasons for that :
 - a dumb misunderstanding between filter and function call on Twig
 - a bad configuration on the Twig Extension. Regarding to official
documentation, functions has to be registered on getGlobals() where in
fact getFunctions() now exists and is dedicaded for that.
I guess http://www.twig-project.org/doc/extensions.html#globals-and-functions
should be updated.

Regards

PS : btw Twig is really nice, I love it.

On 24 jan, 10:36, Fabien Potencier <fabien.potenc...@symfony-
project.com> wrote:
> On 1/24/11 5:02 PM, Jérôme TEXIER wrote:
>
> > Hi Fabien,
>
> > My question is just what is the best way to use some user-defined
> > helper functions (for instance a bread crumb function) onTwig.
> > Before PR5, I was injecting helper class (Templating\Helper
> > \FooHelper.php) on the view and had access to those functions via the
> > former _view variable.
>
> > I was thinking on how to use those functions now without the _view
> > variable.
> > I understand now that I simply should define those functions as
> > Twig_Function_Method on a TwigExtension.
>
> Two possibilities:
>
>   * create aTwigfunction (so you have {{ foo() }})
>   * register a global variable (so you have {{ foo.bar() }})
>
> Fabien
>
>
>
>
>
>
>
>
>
> > On 24 jan, 00:48, Fabien Potencier<fabien.potenc...@symfony-
> > project.com>  wrote:
> >> On 1/24/11 5:20 AM, Jérôme TEXIER wrote:
>
> >>> Hello,
>
> >>> sincehttps://github.com/symfony/symfony/commit/b60d254be2f9b9a8b1340a8f7b4...
> >>> _view variable no more exist on templates.
> >>> Before PR5, I was using this variable to access to some injectedTwig
> >>> helper functions.
> >>> It doesn't seem really clear to me now what it's best way to do it now
> >>> without this variable.
> >>> Should we use request global variable to get a defined helper
> >>> service ?
>
> >> Can you give me an example of what you are trying to do?
>
> >> Fabien

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to