T
T
test0962021-09-24 23:15:21
Twig
test096, 2021-09-24 23:15:21

How to convert to twig syntax?

foreach ($data as $elem) {
    $img = empty($elem['thumbnail_url']) ? $elem['media_url'] : $elem['thumbnail_url'];
    echo  '<a href="' . $elem['permalink'] . '" class="social__item">
            <img src="' . $img . '"/>
          </a>';
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2021-09-24
@test096

{% for elem in data %}
    <a href="{{ elem.permalink }}" class="social__item">
        <img src="{{ elem.thumbnail_url ?: elem.media_url }}"/>
    </a>
{% endfor %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question