From cb732490a3273baee35288e4ba4462e6cfc9839c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 2 Mar 2015 18:29:18 +0100 Subject: [PATCH] removed an obsolete recipe --- doc/api.rst | 4 +++- doc/recipes.rst | 50 ------------------------------------------------- 2 files changed, 3 insertions(+), 51 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index 3ff5d1a2a..cdeaffdb0 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -106,7 +106,9 @@ The following options are available: to avoid collision with built-in escaping strategies). As of Twig 1.17, the ``filename`` escaping strategy determines the escaping - strategy to use for a template based on the template filename extension. + strategy to use for a template based on the template filename extension (this + strategy does not incur any overhead at runtime as auto-escaping is done at + compilation time.) * ``optimizations``: A flag that indicates which optimizations to apply (default to ``-1`` -- all optimizations are enabled; set it to ``0`` to diff --git a/doc/recipes.rst b/doc/recipes.rst index 64090d913..86cede630 100644 --- a/doc/recipes.rst +++ b/doc/recipes.rst @@ -316,56 +316,6 @@ This can be easily achieved with the following code:: return $node; } -Using the Template name to set the default Escaping Strategy ------------------------------------------------------------- - -.. versionadded:: 1.8 - This recipe requires Twig 1.8 or later. - -The ``autoescape`` option determines the default escaping strategy to use when -no escaping is applied on a variable. When Twig is used to mostly generate -HTML files, you can set it to ``html`` and explicitly change it to ``js`` when -you have some dynamic JavaScript files thanks to the ``autoescape`` tag: - -.. code-block:: jinja - - {% autoescape 'js' %} - ... some JS ... - {% endautoescape %} - -But if you have many HTML and JS files, and if your template names follow some -conventions, you can instead determine the default escaping strategy to use -based on the template name. Let's say that your template names always end -with ``.html`` for HTML files, ``.js`` for JavaScript ones, and ``.css`` for -stylesheets, here is how you can configure Twig:: - - class TwigEscapingGuesser - { - function guess($filename) - { - // get the format - $format = substr($filename, strrpos($filename, '.') + 1); - - switch ($format) { - case 'js': - return 'js'; - case 'css': - return 'css'; - case 'html': - default: - return 'html'; - } - } - } - - $loader = new Twig_Loader_Filesystem('/path/to/templates'); - $twig = new Twig_Environment($loader, array( - 'autoescape' => array(new TwigEscapingGuesser(), 'guess'), - )); - -This dynamic strategy does not incur any overhead at runtime as auto-escaping -is done at compilation time. - Using a Database to store Templates -----------------------------------