url_*()

url()

The url() function generates a fully qualified URL to the given path.

{{ url('blog') }}

{#  https://site.com/blog #}

You can specify a variable as a function parameter:

{{ url(category.slug) }}

{#  https://site.com/slug-value #}

In function parameters you can use concatenation:

{{ url('blog/post/' ~ post.id) }}

{#  https://site.com/blog/post/123 #}

Base URL

You can get the base url like this:

{{ url('/') }}

{#  https://site.com/ #}

url_current()

The url_current() function generates a fully qualified URL to the current path. Syntax:

{{ url_current() }}

An example of generating a canonical link using the url_current() function and the |lower Twig filter:

<link rel="canonical" href="{{ url_current()|lower }}" />
Copyright © 2024 Winter CMS