This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

gavinfostered11132
gavinfostered11132

How can I use the str_limit() function with twig?

My component template looks like this:

{% for intro in intros %}
<a href="{{ intro.page_link|raw }}" class="small-12 columns intro">
<div class="intro__icon">
    <i class="fa {{ intro.icon|raw }} fa-2x"></i>
</div>
<div class="intro__body">
    <h3 class="heading--intro">{{ intro.title|raw }}</h3>
    <p>{{ intro.content|raw }}</p>
</div>
</a>
{% endfor %}

I want to limit intro.content to 100 characters. I've tried the following:

{{ str_limit('{{ intro.content|raw }}', 100) }}

{{ str_limit('{ intro.content|raw }', 100) }}

{{ str_limit(' intro.content|raw ', 100) }}

Nothing seems to work. Am I using str_limit incorrectly?

Vannut
Vannut

According to the documentation this should work:

{{ str_limit('The quick brown fox...', 100, '... Read more!') }}

in: http://octobercms.com/docs/markup/function-str

Last updated

alxy
alxy

The correct syntax is : {{ str_limit(intro.content|raw , 100) }}

gavinfostered11132
gavinfostered11132

alxy said:

The correct syntax is : {{ str_limit(intro.content|raw , 100) }}

Thank you very much alxy! Works perfectly :D

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.