mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-25 21:26:36 +00:00
removed the deprecated filter tag
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 3.0.0 (2019-XX-XX)
|
||||
|
||||
* removed the "filter" tag
|
||||
* added type hints everywhere
|
||||
* changed Environment::resolveTemplate() to always return a TemplateWrapper instance
|
||||
* removed Template::__toString()
|
||||
|
||||
@@ -395,11 +395,6 @@ Most of the time though, a tag is not needed:
|
||||
Much better than creating a tag as you can **compose** filters.
|
||||
{% endapply %}
|
||||
|
||||
.. note::
|
||||
|
||||
The ``apply`` tag was introduced in Twig 2.9; use the ``filter`` tag with
|
||||
previous versions.
|
||||
|
||||
* If your tag does not output anything, but only exists because of a side
|
||||
effect, create a **function** that returns nothing and call it via the
|
||||
:doc:`filter <tags/do>` tag.
|
||||
|
||||
@@ -27,11 +27,6 @@ on large amounts of HTML:
|
||||
|
||||
{# output will be <div><strong>foo</strong></div> #}
|
||||
|
||||
.. note::
|
||||
|
||||
The ``apply`` tag was introduced in Twig 2.9; use the ``filter`` tag with
|
||||
previous versions.
|
||||
|
||||
This tag is not meant to "optimize" the size of the generated HTML content but
|
||||
merely to avoid extra whitespace between HTML tags to avoid browser rendering
|
||||
quirks under some circumstances.
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
``apply``
|
||||
=========
|
||||
|
||||
.. versionadded:: 2.9
|
||||
The ``apply`` tag was added in Twig 2.9.
|
||||
|
||||
The ``apply`` tag allows you to apply Twig filters on a block of template data:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
``filter``
|
||||
==========
|
||||
|
||||
.. note::
|
||||
|
||||
As of Twig 2.9, you should use the ``apply`` tag instead which does the
|
||||
same thing except that the wrapped template data is not scoped.
|
||||
|
||||
Filter sections allow you to apply regular Twig filters on a block of template
|
||||
data. Just wrap the code in the special ``filter`` section:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% filter upper %}
|
||||
This text becomes uppercase
|
||||
{% endfilter %}
|
||||
|
||||
You can also chain filters and pass arguments to them:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% filter lower|escape('html') %}
|
||||
<strong>SOME TEXT</strong>
|
||||
{% endfilter %}
|
||||
|
||||
{# outputs "<strong>some text</strong>" #}
|
||||
@@ -179,11 +179,6 @@ To apply a filter on a section of code, wrap it in the
|
||||
Go to the :doc:`filters<filters/index>` page to learn more about built-in
|
||||
filters.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``apply`` tag was introduced in Twig 2.9; use the ``filter`` tag with
|
||||
previous versions.
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ use Twig\TokenParser\DeprecatedTokenParser;
|
||||
use Twig\TokenParser\DoTokenParser;
|
||||
use Twig\TokenParser\EmbedTokenParser;
|
||||
use Twig\TokenParser\ExtendsTokenParser;
|
||||
use Twig\TokenParser\FilterTokenParser;
|
||||
use Twig\TokenParser\FlushTokenParser;
|
||||
use Twig\TokenParser\ForTokenParser;
|
||||
use Twig\TokenParser\FromTokenParser;
|
||||
@@ -180,7 +179,6 @@ final class CoreExtension extends AbstractExtension
|
||||
new IncludeTokenParser(),
|
||||
new BlockTokenParser(),
|
||||
new UseTokenParser(),
|
||||
new FilterTokenParser(),
|
||||
new MacroTokenParser(),
|
||||
new ImportTokenParser(),
|
||||
new FromTokenParser(),
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Node\BlockNode;
|
||||
use Twig\Node\Expression\BlockReferenceExpression;
|
||||
use Twig\Node\Expression\ConstantExpression;
|
||||
use Twig\Node\PrintNode;
|
||||
use Twig\Token;
|
||||
|
||||
/**
|
||||
* Filters a section of a template by applying filters.
|
||||
*
|
||||
* {% filter upper %}
|
||||
* This text becomes uppercase
|
||||
* {% endfilter %}
|
||||
*
|
||||
* @deprecated since Twig 2.9, to be removed in 3.0 (use the "apply" tag instead)
|
||||
*/
|
||||
final class FilterTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
@trigger_error('The "filter" tag is deprecated since Twig 2.9, use the "apply" tag instead.', E_USER_DEPRECATED);
|
||||
|
||||
$name = $this->parser->getVarName();
|
||||
$ref = new BlockReferenceExpression(new ConstantExpression($name, $token->getLine()), null, $token->getLine(), $this->getTag());
|
||||
|
||||
$filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
|
||||
$this->parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3);
|
||||
|
||||
$body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
|
||||
$this->parser->getStream()->expect(/* Token::BLOCK_END_TYPE */ 3);
|
||||
|
||||
$block = new BlockNode($name, $body, $token->getLine());
|
||||
$this->parser->setBlock($name, $block);
|
||||
|
||||
return new PrintNode($filter, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Token $token)
|
||||
{
|
||||
return $token->test('endfilter');
|
||||
}
|
||||
|
||||
public function getTag()
|
||||
{
|
||||
return 'filter';
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
--TEST--
|
||||
"filter" tag applies a filter on its children
|
||||
--DEPRECATION--
|
||||
The "filter" tag is deprecated since Twig 2.9, use the "apply" tag instead.
|
||||
--TEMPLATE--
|
||||
{% filter upper %}
|
||||
Some text with a {{ var }}
|
||||
{% endfilter %}
|
||||
--DATA--
|
||||
return ['var' => 'var']
|
||||
--EXPECT--
|
||||
SOME TEXT WITH A VAR
|
||||
@@ -1,10 +0,0 @@
|
||||
--TEST--
|
||||
"filter" tag applies a filter on its children
|
||||
--DEPRECATION--
|
||||
The "filter" tag is deprecated since Twig 2.9, use the "apply" tag instead.
|
||||
--TEMPLATE--
|
||||
{% filter json_encode|raw %}test{% endfilter %}
|
||||
--DATA--
|
||||
return []
|
||||
--EXPECT--
|
||||
"test"
|
||||
@@ -1,12 +0,0 @@
|
||||
--TEST--
|
||||
"filter" tags accept multiple chained filters
|
||||
--DEPRECATION--
|
||||
The "filter" tag is deprecated since Twig 2.9, use the "apply" tag instead.
|
||||
--TEMPLATE--
|
||||
{% filter lower|title %}
|
||||
{{ var }}
|
||||
{% endfilter %}
|
||||
--DATA--
|
||||
return ['var' => 'VAR']
|
||||
--EXPECT--
|
||||
Var
|
||||
@@ -1,19 +0,0 @@
|
||||
--TEST--
|
||||
"filter" tags can be nested at will
|
||||
--DEPRECATION--
|
||||
The "filter" tag is deprecated since Twig 2.9, use the "apply" tag instead.
|
||||
The "filter" tag is deprecated since Twig 2.9, use the "apply" tag instead.
|
||||
--TEMPLATE--
|
||||
{% filter lower|title %}
|
||||
{{ var }}
|
||||
{% filter upper %}
|
||||
{{ var }}
|
||||
{% endfilter %}
|
||||
{{ var }}
|
||||
{% endfilter %}
|
||||
--DATA--
|
||||
return ['var' => 'var']
|
||||
--EXPECT--
|
||||
Var
|
||||
Var
|
||||
Var
|
||||
@@ -1,13 +0,0 @@
|
||||
--TEST--
|
||||
"scope" tag creates a new scope
|
||||
--DEPRECATION--
|
||||
The "filter" tag is deprecated since Twig 2.9, use the "apply" tag instead.
|
||||
--TEMPLATE--
|
||||
{% filter spaceless %}
|
||||
{% set item = 'foo' %}
|
||||
{% endfilter %}
|
||||
{{ item }}
|
||||
--DATA--
|
||||
return []
|
||||
--EXCEPTION--
|
||||
Twig\Error\RuntimeError: Variable "item" does not exist in "index.twig" at line 5.
|
||||
@@ -1,15 +0,0 @@
|
||||
--TEST--
|
||||
"filter" tag applies the filter on "for" tags
|
||||
--DEPRECATION--
|
||||
The "filter" tag is deprecated since Twig 2.9, use the "apply" tag instead.
|
||||
--TEMPLATE--
|
||||
{% filter upper %}
|
||||
{% for item in items %}
|
||||
{{ item }}
|
||||
{% endfor %}
|
||||
{% endfilter %}
|
||||
--DATA--
|
||||
return ['items' => ['a', 'b']]
|
||||
--EXPECT--
|
||||
A
|
||||
B
|
||||
@@ -1,31 +0,0 @@
|
||||
--TEST--
|
||||
"filter" tag applies the filter on "if" tags
|
||||
--DEPRECATION--
|
||||
The "filter" tag is deprecated since Twig 2.9, use the "apply" tag instead.
|
||||
--TEMPLATE--
|
||||
{% filter upper %}
|
||||
{% if items %}
|
||||
{{ items|join(', ') }}
|
||||
{% endif %}
|
||||
|
||||
{% if items.3 is defined %}
|
||||
FOO
|
||||
{% else %}
|
||||
{{ items.1 }}
|
||||
{% endif %}
|
||||
|
||||
{% if items.3 is defined %}
|
||||
FOO
|
||||
{% elseif items.1 %}
|
||||
{{ items.0 }}
|
||||
{% endif %}
|
||||
|
||||
{% endfilter %}
|
||||
--DATA--
|
||||
return ['items' => ['a', 'b']]
|
||||
--EXPECT--
|
||||
A, B
|
||||
|
||||
B
|
||||
|
||||
A
|
||||
Reference in New Issue
Block a user