Twig :: url
The url
filter is used to generate URLs to stakx object or assets.
Since
0.1.1
Changelog
- 0.1.2 - The
absolute
argument was added
Usage
url(assetPath, absolute = false)
Parameters
-
(required)
assetPath
: ContentItem | PageView | stringThe URL or stakx object to link to
-
absolute
: boolWhen set to true, use the
url
option from the site configuration
Example Usage
All URLs linking to stakx pages or assets should always be rendered using the url
filter; this will allow for easy to maintain URLs by changing a single value in your _config.yml
file.
The two options in your configuration file that will be used are:
url
baseurl
By setting absolute
to true, the url
value in _config.yml
will be used in the beginning of the returned URL.
Link to a loop of ContentItems.
<ul>
{% for post in collections.posts %}
<li>
<a href="{{ url(post) }}">{{ post.title }}</a>
</li>
{% endfor %}
</ul>
Link to a specific ContentItem.
{{ url(collections.posts['my-blog-post']) }}
Link to a specific static PageView.
{{ url(pages.News) }}
Link to an standalone asset.
{{ url('/assets/images/logo.png') }}