简体   繁体   中英

how do I fix the twig filter from affecting html tags inside?

I'm learning Drupal8 and Twig with Chaz Chumley's book 'Drupal 8 Theming with Twig'. When I put in the code provided I don't get the desired result. (Chapter 3, Filters) The book says to add the following to the page.html.twig file:

{% filter upper %}
<p>{{ name }} is the best cms around.</p>
{% endfilter %}

but the page outputs

 <P>DRUPAL IS THE BEST CMS AROUND.</P>

(Showing the html tags on the page as shown here )

Is there something I'm missing to have the twig filter not change the HTML tags? or is the only solution to put the filter inside the tag? but this filter is supposed to "wrap sections of HTML and variables" so why is it affecting HTML tags?

Can you give this a try:

<p>{{ 'your text'|upper }}</p>

Also, check out https://drupal.stackexchange.com/ if you have any more drupal related questions.

You can put the filter around just the text, so it ends up as:

<p>{% filter upper %}{{ name }} is the best cms around.{% endfilter %}</p>

You can test your twig code here: https://twig.stapps.io/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM