* 0.9.7-DEV
Backward incompatibilities:
- * added a 'as' string to the block tag short notation ({% block title "Title" %} must now be {% block title as "Title" %})
+ * changed 'as' to '=' for the set tag ({% set title as "Title" %} must now be {% set title = "Title" %})
* removed the sandboxed attribute of the include tag (use the new sandbox tag instead)
* refactored the Node system (if you have custom nodes, you will have to update them to use the new API)
-
[twig]
- {% block title as page_title|title %}
+ {% block title page_title|title %}
Import Context Behavior
-----------------------
the `set` tag and can have multiple targets:
[twig]
- {% set foo as 'foo' %}
+ {% set foo = 'foo' %}
- {% set foo as [1, 2] %}
+ {% set foo = [1, 2] %}
- {% set foo as ['foo': 'bar] %}
+ {% set foo = ['foo': 'bar] %}
- {% set foo as 'foo' ~ 'bar' %}
+ {% set foo = 'foo' ~ 'bar' %}
- {% set foo, bar as 'foo', 'bar' %}
+ {% set foo, bar = 'foo', 'bar' %}
The `set` tag can also be used to 'capture' chunks of HTML (new in Twig
0.9.6):
const REGEX_NAME = '/[A-Za-z_][A-Za-z0-9_]*/A';
const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?/A';
const REGEX_STRING = '/(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')/Asm';
- const REGEX_OPERATOR = '/<=? | >=? | [!=]= | \/\/ | \.\. | [(){}.,%*\/+~|-] | \[ | \] | \? | \:/Ax';
+ const REGEX_OPERATOR = '/<=? | >=? | [!=]= | = | \/\/ | \.\. | [(){}.,%*\/+~|-] | \[ | \] | \? | \:/Ax';
public function __construct(Twig_Environment $env = null, array $options = array())
{
}
}
} else {
- $stream->expect(Twig_Token::NAME_TYPE, 'as');
-
$body = new Twig_Node(array(
new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno),
));
$names = $this->parser->getExpressionParser()->parseAssignmentExpression();
$capture = false;
- if ($stream->test(Twig_Token::NAME_TYPE, 'as')) {
+ if ($stream->test(Twig_Token::OPERATOR_TYPE, '=')) {
$stream->next();
list(, $values) = $this->parser->getExpressionParser()->parseMultitargetExpression();
{{ [1, 'foo': 'bar']|keys|join(',') }}
{# nested arrays #}
-{% set a as [1, 2, [1, 2], 'foo': ['foo': 'bar']] %}
+{% set a = [1, 2, [1, 2], 'foo': ['foo': 'bar']] %}
{{ a[2]|join(',') }}
{{ a["foo"]|join(',') }}
"block" tag
--TEMPLATE--
{% block title1 %}FOO{% endblock %}
-{% block title2 as foo|lower %}
+{% block title2 foo|lower %}
--TEMPLATE(foo.twig)--
{% block content %}{% endblock %}
--DATA--
--TEMPLATE--
{% for i in 1..2 %}
{% for j in 0..2 %}
- {{k}}{% set k as k+1 %} {{ loop.parent.loop.index }}
+ {{k}}{% set k = k+1 %} {{ loop.parent.loop.index }}
{% endfor %}
{% endfor %}
--DATA--
--TEST--
"set" tag
--TEMPLATE--
-{% set foo as 'foo' %}
+{% set foo = 'foo' %}
{{ foo }}
-{% set foo, bar as 'foo', 'bar' %}
+{% set foo, bar = 'foo', 'bar' %}
{{ foo }}{{ bar }}
--DATA--
--- /dev/null
+--TEST--
+"set" tag block capture
+--TEMPLATE--
+{% set foo %}foo{% endset %}
+
+{{ foo }}
+--DATA--
+return array()
+--EXPECT--
+foo
--TEST--
"set" tag
--TEMPLATE--
-{% set foo, bar as 'foo' ~ 'bar', 'bar' ~ 'foo' %}
+{% set foo, bar = 'foo' ~ 'bar', 'bar' ~ 'foo' %}
{{ foo }}
{{ bar }}