removed an obsolete recipe

This commit is contained in:
Fabien Potencier
2015-03-02 18:29:18 +01:00
parent 11f9ebe8b6
commit cb732490a3
2 changed files with 3 additions and 51 deletions
+3 -1
View File
@@ -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
-50
View File
@@ -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
-----------------------------------