Twig Components / Methods / redirect
Note: You are currently reading the documentation for Bolt 5.0. Looking for the documentation for Bolt 5.2 instead?
redirect(path)
is a Twig function to redirect from a page to another page or domain. Commonly
used in an if/else clause, to redirect visitors based on some criteria.
{% if record.image!="" %}
<a href="{{ image(record.image) }}">
<img src="{{ thumbnail(record.image, 400, 260) }}">
</a>
{% else %}
{# passive-aggressive way to tell people to find their own image #}
{{ redirect('http://images.google.com/') }}
{% endif %}
{% setcontent records = "pages" limit latest 5 %}
{% for record in records %}
<h2><a href="{{ record|link }}">{{ record.title }}</a></h2>
<p>{{ record.excerpt() }}</p>
{% else %}
{{ redirect(path('homepage')) }} or {{ redirect('page/some-page') }}
{% endfor %}
Edit this page on GitHub
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on Github.
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on Github.