I created a filter in Twig that wraps some HTML around the output. E.g.
{{ 'this is a "test"'|display }}
outputs
<div id="container">
<div id="content">
this is a "test"
</div>
<div id="toolbar">
<a href="/edit.php">edit</a>
</div>
</div>
The dilemma is, I would like that subsequent filters are applied only on the original content, and not on the entire html. E.g.
{{ 'this is a "test"'|display|upper|e }}
outputs
<DIV ID="CONTAINER">
<DIV ID="CONTENT">
THIS IS A "TEST"
</DIV>
<DIV ID="TOOLBAR">
<A HREF="/EDIT.PHP">EDIT</A>
</DIV>
</DIV>
but as you can imagine, I would prefer the output like this
<div id="container">
<div id="content">
THIS IS A "TEST"
</div>
<div id="toolbar">
<a href="/edit.php">edit</a>
</div>
</div>
Changing the filter order to
{{ 'this is a "test"'|upper|e|display }}
would work for the upper filter, but not for the escape filter, because it places itself always at the end of the filter queue. Also it should work with autoescape=true.
Reading the twig documentation, I can’t find a standard way to do what I want. Has someone maybe tried something similar? Or has someone an idea to work around the problem?
Thanks in advance!
Try:
Filter your content in first place and then wrap it.