Search code examples
htmlcsstwig

Get a string from a text field using twig and craft CMS


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 %}

Solution

  • 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.