Link Generators in Twig


#1

Hey all,

Based on this link.

There is a example using plain php for views.

I’m new on Twig so how do you apply this example in Twig:

<ul class="foo">
    <?php foreach($this->newsList as $news) { ?>
        <a href="<?= $app->getContainer()->get('website.news_linkgenerator')->generate($news); ?>"><?= $news->getTitle() ?></a>
    <?php } ?>
</ul>

#2

Hi,

<ul class="foo">
    {% for news in newsList %}
        <a href="{{ app.container.get('website.news_linkgenerator').generate(news)  }}">
            {{ news.getTitle }}
        </a>
    {% endfor %}
</ul>

like this.

NOTE: this is untested and could contain syntax issues :wink:

Regards
Dominik