Hand-written Includes in-depth notes
Language Switcher lang_switcher
Used inside components
Render the language switcher, whose links point to the target-language version of the same content instead of the home page.
lang_switcher(array $options = [])
Pages Site-wide (system)
How do I read these repository paths?
All paths are relative to the site root. Open core/tpl_functions.php at line 143 to see the definition of lang_switcher(). The "core method" is what the tag actually forwards to: a template writes content_list(...) and the core runs Tpl::contentList(...).
1. Fill in parameters, get the code Edit any field and the result below updates instantly; press Copy and paste it into a template. It also works without JavaScript: press Generate and the server recomputes it.
click the title to collapse / expand
Now generating: lang_switcher
This is the real rendering of the page (real header, container, this tag output, real footer). It reloads when you change a parameter.
Refreshing…
This is the server-computed default; it updates as you edit any parameter and the preview on the right is re-rendered too. It also works without JavaScript: fill the form and press Generate.
2. Full parameter table 2 parameters, one per row; scroll sideways on narrow screens.
click the title to collapse / expand
| Parameter | Type | Default | Description |
|---|---|---|---|
class |
string |
Auto | Class for the outer div; defaults to ry-lang and is replaced entirely when set. |
style |
string |
text | Defaults to the admin setting text or flag; any other value, dropdown included, renders plain text links. |
3. Examples Every example can be copied as-is; the later ones are more advanced.
click the title to collapse / expand
Smallest working call
Prints the language links for the current page with the active class on the current language, all pointing at the same content.
<?= lang_switcher() ?>
Typical header usage
The class option replaces the factory class, so ry-lang has to be repeated; the wrapper owns position and spacing.
<div class="ry-header__lang">
<?= lang_switcher(['class' => 'ry-lang ry-header__lang-list', 'style' => 'text']) ?>
</div>
Advanced: dropdown layout inside a drawer
Switch the layout with style; the pack provides the collapsed panel styles while the tag only prints the links.
<div class="ry-drawer__lang">
<?= lang_switcher(['class' => 'ry-lang ry-lang--dropdown', 'style' => 'dropdown']) ?>
</div>
4. What it does / when to use it
Use it whenever a bilingual or multilingual site needs a language entry point for visitors: the top right of the header, a mobile drawer, or a language bar on a standalone landing page all work. Its value is that every link points at the target-language version of the same content, using the alternates the controller already computed, instead of dropping visitors back on the home page. Single-language sites do not need it, and it does not replace the SEO output in the page head, which owns hreflang and canonical.
5. Which pages it belongs on This is the question clients actually ask: "I am building the home page / a list page / a detail page — which tags do I use?"
click the title to collapse / expand
| Page | What that page is | What this tag does there |
|---|---|---|
| Site-wide (system) | Header, footer, head, styles and scripts — every page template needs them |
It is a system tag written once per page template, inside the page shell (head, header, footer, scripts). You use it to: Use it whenever a bilingual or multilingual site needs a language entry point for visitors: the top right of the header, |
Clicking a page name jumps to every tag for that page in the reference (the "By page" filter there). This page always shows everything about the tag, whatever that filter is set to.
6. How to use it (step by step)
- Start with a bare lang_switcher() call in the header template and confirm that it lists exactly the languages enabled in the admin and that the current language carries the active class.
- Pass class together with the factory class, because the option replaces the default ry-lang: write ['class' => 'ry-lang my-header__lang'] to keep the spacing and the active highlight.
- Choose the layout with style: text renders a flat row of text links, while dropdown is meant for a collapsed panel whose open and close states come from your wrapper and the pack CSS.
- Give the wrapper its own container class when you place it in a mobile drawer or a standalone language bar, so its colour and size do not depend on the header grid.
- Verify by switching the language once before release: translated content should open the same article in the other language, and untranslated content should fall back to that language home page rather than a 404.
7. Common pitfalls
- Passing only your own class drops ry-lang, so the gap between language links and the active highlight disappear. Keep the factory class inside the value.
- Never hand-build URLs such as /en/some-page.html: translated paths go through language pairing and prefix handling, and a hand-written link becomes a dead link after a rename, an unpublish, or a missing translation.
- When the target language has no translation, the link falls back to that language home page by design. Do not work around it in the template because a visitor landed on a home page.
- Languages that are disabled in the admin never appear in the output, and with a single enabled language the tag still prints one link to the current page, which looks like a current-language button and never hides itself.
- Passing dropdown without matching collapsed styles leaves a flat row of language links that looks like a broken dropdown. Ship the layout class and its CSS together.
Note from the reference table Two corrections: style only honours text and flag, so dropdown renders plain links; and an untranslated language is absent from alternates, so the link becomes the same path under another language prefix and the admin missing-translation action applies (default: redirect to the default-language version), never that language's home page.
style only honours text and flag, so dropdown renders plain links; and an untranslated language is absent from alternates, so the link becomes the same path under another language prefix and the admin missing-translation action applies (default: redirect to the default-language version), never that language's home page.8. Real rendered output This section was rendered once on the server with this site real data; it is not a mock-up.
click the title to collapse / expand
It outputs a whole page region (this site header / footer / a full layout section, or it decides what to render from the current page data). Inside this small box it would just splice another page skeleton into this one: you would not see its real effect, and it would wreck this page. Copy it into your template instead.
Loading the code…
9. Where it already appears in your templates Grouped by components / page templates / template packs; the data comes from a script scan.
click the title to collapse / expand
Components 20 files / 38 calls 89% of tag calls live in components
-
templates/_shared/components/header.php×3 lines 133, 186, 222 -
templates/_shared/components/header-autohide.php×2 lines 298, 331 -
templates/_shared/components/header-compact.php×2 lines 317, 353 -
templates/_shared/components/header-drawer.php×2 lines 354, 387 -
templates/_shared/components/header-floating.php×2 lines 271, 303 -
templates/_shared/components/header-fullscreen.php×2 lines 477, 552 -
templates/_shared/components/header-glass.php×2 lines 335, 370 -
templates/_shared/components/header-gradient.php×2 lines 373, 396
Click "See this code + preview": the left shows the real code around that call site (±12 lines, call line highlighted) and the right renders a real page preview with the current parameters.