From 34bfda364c48178d0415689c1ba9233d59a4e6c2 Mon Sep 17 00:00:00 2001 From: fabien Date: Tue, 27 Oct 2009 13:05:14 +0000 Subject: [PATCH] added some more information about creating a filter with some arguments git-svn-id: http://svn.twig-project.org/trunk@101 93ef8e89-cb99-4229-a87c-7fa0fa45744b --- doc/04-Extending-Twig.markdown | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/doc/04-Extending-Twig.markdown b/doc/04-Extending-Twig.markdown index 7cd7294..e8041ad 100644 --- a/doc/04-Extending-Twig.markdown +++ b/doc/04-Extending-Twig.markdown @@ -100,7 +100,7 @@ Registering the new extension is like registering core extensions: $twig->addExtension(new Project_Twig_Extension()); Filters can also be passed the current environment. You might have noticed -that a filter is defined by a callable and a Boolean. If you change the +that a filter is defined by a function name and a Boolean. If you change the Boolean to `true`, Twig will pass the current environment as the first argument to the filter call: @@ -125,6 +125,23 @@ argument to the filter call: return str_rot13($string); } +Parameters passed to the filter are available as extra arguments to the +function call: + + [twig] + {{ "Twig"|rot13('prefix_') }} + +- + + [php] + function twig_compute_rot13(Twig_Environment $env, $string, $prefix = '') + { + // get the current charset for instance + $charset = $env->getCharset(); + + return $prefix.str_rot13($string); + } + Defining new Tags ----------------- -- 1.7.2.5