content_url - Twig Function
Info
This feature is available in Contao 5.3 and later.
This function is similar to Symfony’s path
.
It will generate an URL for the given model using Contao’s
Content URL Generation. This is useful for controllers that list
your items - and the items are passed as an iterable collection of Models.
{# templates/frontend_module/foobar_list.html.twig #}
{% extends "@Contao/frontend_module/_base.html.twig" %}
{% block content %}
{% for item in items %}
<div class="item">
<a href="{{ content_url(item) }}">{{ item.title }}</a>
</div>
{% endfor %}
{% endblock %}
Arguments
content
: The Contao model to generate the URL for.parameters
: Optional array of parameters. This can be useful for page models in order to set URL parameters.relative
: By default the function always creates an absolute URL. By passingtrue
it will be an absolute path instead.