skip to Main Content

I am using twig and craft CMS.

How can I access just one word from a text field and underline it?
As an example of what I want the result to be, I have provided a HTML and CSS code.

<p>
    Lorem Ipsum is simply dummy text of the
    <span>printing</span> and
    <span>typesetting</span> industry.
</p>
span {
    text-decoration: underline;
}

That’s the code that I use in twig

{% for text in texts %}
    <div class="col-12 col-md-8">
        <h1>{{ text.title }}</h1>
    </div>
{% endfor %}

2

Answers


  1. Chosen as BEST ANSWER

    I found a way around it by changing the field type to Redactor. This way I was able to edit the text with HTML. It is also possible to edit the Redactor config file (craft/config/redactor/) and add buttons for editting.

    "buttons": ["bold", "italic", "underline"]
    

    This is the documentation I used.


  2. The text field may be divided into an array of words using Twig’s split filter, and you can then use the array’s index to get the desired word.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search