Helpful in Twig Templates. Allows you to set a static referer that can be set across multiple page views using the session to get back to a specific page using a Twig function. This can be used to generate a "Back" button.
First you need to add tenolo/referer-bundle
to composer.json
:
Let Composer do it for you.
$ composer require tenolo/referer-bundle
or do it manually
{
"require": {
"tenolo/referer-bundle": "~1.0"
}
}
Please note that dev-master
latest development version.
Of course you can also use an explicit version number, e.g., 1.0.*
.
{# check for a static referer #}
{% if referer_has() %}
<a href="{{ referer_uri() }}">Go back</a>
{% endif %}
If no static referer was set, the referer from the header of the request is used.
<a href="{{ path('route_name_of_next_page', { param: value })|referer_query }}">Next Page</a>
The link is manipulated so that the library remembers the current page. If the Twig function "referer_uri" is called on one of the later pages, a link is generated that links back to the current page.