Score:0

How to strip tags/ or just trim content but preserve ampersand in field content

jp flag

enter image description here

The issue : striptags removes "&" from the fields content as well.

{{ label }} preservers the "&" but I am not able to trim the content. I have twig_extender enabled

 <div class="card__back back">
    <div class="back__content__container">
      <div class="program_title--copy">
        {% set text = label|render|striptags|trim %}
        {{ text|length > 40 ? text|truncate(40, true, true) : text }}
      </div>
      <hr />
      <div class="program-banner-subtext">
        {% set text = content.field_banner_subtext[0]['#context']['value']|trim %} {# This option works #}
        {{ text|length > 110 ? text|truncate(110, true, true) : text }}
      </div>
    </div>
leymannx avatar
ne flag
You should rather use field formatters under the display settings of your entity.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.