Permalink
Browse files

renamed |safe to |raw to avoid unnecesarry confusion about what the t…

…ags does.

Discussion can be viewed here http://groups.google.com/group/symfony-devs/browse_thread/thread/b927063310c74411. All tests pass.
  • Loading branch information...
1 parent 15f3276 commit 56caee09379e5b795ba0405b721aa997f8afa876 @henrikbjorn henrikbjorn committed with Oct 1, 2010
View
@@ -4,6 +4,7 @@ Backward incompatibilities:
* the self special variable has been renamed to _self
* the odd and even filters are now tests:
{{ foo|odd }} must now be written {{ foo is odd }}
+ * the "safe" filter has been renamed to "raw"
* the implementation of template inheritance has been rewritten
(blocks can now be called individually and still work with inheritance)
@@ -434,7 +434,7 @@ template to be escaped or not by using the `autoescape` tag:
When automatic escaping is enabled everything is escaped by default except for
values explicitly marked as safe. Those can be marked in the template by using
-the `|safe` filter.
+the `|raw` filter.
Functions returning template data (like macros and `parent`) always return
safe markup.
@@ -1198,14 +1198,14 @@ might contain such characters in HTML.
>**NOTE**
>Internally, `escape` uses the PHP `htmlspecialchars` function.
-### `safe`
+### `raw`
-The `safe` filter marks the value as safe which means that in an environment
+The `raw` filter marks the value as safe which means that in an environment
with automatic escaping enabled this variable will not be escaped.
[twig]
{% autoescape on }
- {{ var|safe }} {# var won't be escaped #}
+ {{ var|raw }} {# var won't be escaped #}
{% autoescape off %}
### `constant` (new in Twig 0.9.9)
@@ -299,7 +299,7 @@ registered by default.
### Escaper Extension
The `escaper` extension adds automatic output escaping to Twig. It defines a
-new tag, `autoescape`, and a new filter, `safe`.
+new tag, `autoescape`, and a new filter, `raw`.
When creating the escaper extension, you can switch on or off the global
output escaping strategy:
@@ -309,17 +309,17 @@ output escaping strategy:
$twig->addExtension($escaper);
If set to `true`, all variables in templates are escaped, except those using
-the `safe` filter:
+the `raw` filter:
[twig]
- {{ article.to_html|safe }}
+ {{ article.to_html|raw }}
You can also change the escaping mode locally by using the `autoescape` tag:
[twig]
{% autoescape on %}
{% var %}
- {% var|safe %} {# var won't be escaped #}
+ {% var|raw %} {# var won't be escaped #}
{% var|escape %} {# var won't be doubled-escaped #}
{% endautoescape %}
@@ -345,21 +345,21 @@ Twig 0.9.5 and above):
[twig]
{{ var|nl2br }} {# is equivalent to {{ var|escape|nl2br }} #}
- * The `safe` filter can be used anywhere in the filter chain:
+ * The `raw` filter can be used anywhere in the filter chain:
[twig]
- {{ var|upper|nl2br|safe }} {# is equivalent to {{ var|safe|upper|nl2br }} #}
+ {{ var|upper|nl2br|raw }} {# is equivalent to {{ var|raw|upper|nl2br }} #}
* Automatic escaping is applied to filter arguments, except for literals:
[twig]
{{ var|foo("bar") }} {# "bar" won't be escaped #}
{{ var|foo(bar) }} {# bar will be escaped #}
- {{ var|foo(bar|safe) }} {# bar won't be escaped #}
+ {{ var|foo(bar|raw) }} {# bar won't be escaped #}
* Automatic escaping is not applied if one of the filters in the chain has the
`is_escaper` option set to `true` (this is the case for the built-in
- `escaper`, `safe`, and `urlencode` filters for instance).
+ `escaper`, `raw`, and `urlencode` filters for instance).
### Sandbox Extension
@@ -45,7 +45,7 @@ public function getNodeVisitors()
public function getFilters()
{
return array(
- 'safe' => new Twig_Filter_Function('twig_safe_filter', array('is_escaper' => true)),
+ 'raw' => new Twig_Filter_Function('twig_raw_filter', array('is_escaper' => true)),
);
}
@@ -66,7 +66,7 @@ public function getName()
}
// tells the escaper node visitor that the string is safe
-function twig_safe_filter($string)
+function twig_raw_filter($string)
{
return $string;
}
@@ -5,7 +5,7 @@
{{ var|nl2br("<br />") }}
{{ var|nl2br("<br />"|escape) }}
{{ var|nl2br(sep) }}
-{{ var|nl2br(sep|safe) }}
+{{ var|nl2br(sep|raw) }}
{% endautoescape %}
--DATA--
return array('var' => "<Fabien>\nTwig", 'sep' => '<br />')
@@ -1,8 +1,8 @@
--TEST--
-"autoescape" tag does not escape when safe is used as a filter
+"autoescape" tag does not escape when raw is used as a filter
--TEMPLATE--
{% autoescape on %}
-{{ var|safe }}
+{{ var|raw }}
{% endautoescape %}
--DATA--
return array('var' => '<br />')

0 comments on commit 56caee0

Please sign in to comment.