Page variables in content blocks
One header, footer or content block that adapts to the page it is shown on: a large header photo on the homepage and a small one elsewhere, a tip on the search page only, or a promo banner that disappears during checkout. You do this with the page variables, through the modifier ires_page. They work in every content block, including the header and footer blocks of a theme.
The page variables
| Variable | Value |
|---|---|
{"path"|ires_page} | Path of the page without query string, e.g. /overzicht. |
{"uri"|ires_page} | Path plus query string, e.g. /overzicht?cat=3. |
{"mod"|ires_page} | The module of the page, also behind an SEO url. E.g. searchevents, calendar, checkout, paymentresult. |
{"rewrite"|ires_page} | The SEO alias of the page. |
{"lang"|ires_page} | The current language, e.g. NL or EN. |
{"<parameter>"|ires_page} | Any other parameter of the page. |
Values are cleaned: no HTML or quotes, and at most 255 characters. If a value is empty or the parameter does not exist, you get nothing back. That is why |default:"..." simply works:
<body class="page-{"mod"|ires_page|default:"content"}">Inserting from the editor
In the content block editor, the right-hand panel has the group Page variables at the top. Click a variable to insert it at the cursor. It also contains ready-made if examples you can adapt straight away. More about the side panel in How do I build a content block with variables?.
Examples
1. Large header photo on the homepage, small one elsewhere
{if "path"|ires_page == "/" || "path"|ires_page == "/start"}
<img src="/images/header-groot.jpg" class="header header-groot" alt="">
{else}
<img src="/images/header-klein.jpg" class="header header-klein" alt="">
{/if}2. A tip on the search page only
{if "mod"|ires_page == "searchevents"}
<div class="alert alert-info">Tip: filter op datum om sneller een plek te vinden.</div>
{/if}3. Hide a promo banner during checkout and payment
A calm last step means fewer drop-offs.
{if "mod"|ires_page != "checkout" && "mod"|ires_page != "paymentresult"}
<div class="promo-banner">Nu 10% korting met code HERFST</div>
{/if}4. Text per language
<a href="/boeken" class="btn btn-primary">
{if "lang"|ires_page == "EN"}Book now{elseif "lang"|ires_page == "DE"}Jetzt buchen{else}Nu boeken{/if}
</a>5. React to part of the url
With |strstr:"..." you test whether a text occurs in the path, for example on every page whose url contains kalender.
{if "path"|ires_page|strstr:"kalender"}
<p>Kies hieronder een dag in de kalender.</p>
{/if}From REQUEST_URI to ires_page
For security reasons $smarty.server, $smarty.session, $smarty.cookies and similar variables are not allowed in content blocks. The block then shows a notice instead of its content. The old {$smarty.server.REQUEST_URI} keeps working: it is translated automatically to {"uri"|ires_page}. In new blocks, use ires_page. Query-string values via {$smarty.get.name} remain allowed.
Before:
{if $smarty.server.REQUEST_URI == "/overzicht"} ... {/if}Now:
{if "uri"|ires_page == "/overzicht"} ... {/if}
{* or, ignoring the query string: *}
{if "path"|ires_page == "/overzicht"} ... {/if}Tip: look at the values
Not sure which value a page has? Put this in the block temporarily, open the page, and remove the line afterwards:
<small>mod: {"mod"|ires_page} | path: {"path"|ires_page} | lang: {"lang"|ires_page}</small>

