Macbernie
Macbernie

Reputation: 1323

Print an item with a specific id

I just want to print with twig, the "content" with "id" 1. So this is working:

{% for this in warning %}
    {%  if this.id == 1 %}
        {{ this.content| raw }}
    {% endif %}
{% endfor %}

But how can I do to do the same in the most simply syntax ?

Thanks for help

Upvotes: 0

Views: 49

Answers (2)

Javad
Javad

Reputation: 4397

Base on you comment for Corzin's answer you can try

{% for this in warning %}
   {{ this.id == 1 ? this.content|raw : '' }}
{% endfor %}

But I think Corzin's answer is the best solution

Upvotes: 0

Crozin
Crozin

Reputation: 44376

You could use a for .. in .. if syntax:

{% for this in warning if this.id == 1 $}
    {{ this.content | raw }}
{% endfor %}

Upvotes: 2

Related Questions