21.10.2015 Views

1-33

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Symfony2 – Franz Jordán 2011<br />

To link to the page, just use the path Twig function and refer to the route:<br />

Home<br />

As expected, this will generate the URL /. Let's see how this works with a more complicated<br />

route:<br />

article_show:<br />

pattern: /article/{slug}<br />

defaults: { _controller: AcmeArticleBundle:Article:show }<br />

In this case, you need to specify both the route name (article_show) and a value for<br />

the {slug}parameter. Using this route, let's revisit the recentList template from the<br />

previous section and link to the articles correctly:<br />

{# src/Acme/ArticleBundle/Resources/views/Article/recentList.html.twig #}<br />

{% for article in articles %}<br />

<br />

{{ article.title }}<br />

<br />

{% endfor %}<br />

You can also generate an absolute URL by using the url Twig function:<br />

Home<br />

The same can be done in PHP templates by passing a third argument to<br />

thegenerate() method:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!