PHPackages                             ianreid/switcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. ianreid/switcher

ActiveCraft-plugin[Localization &amp; i18n](/categories/localization)

ianreid/switcher
================

A flexible and easy-to-use sites switcher for Craft CMS.

2.0.0(4mo ago)06052MITPHPPHP ^8.2

Since Mar 15Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/ianreidlangevin/craftcms-switcher)[ Packagist](https://packagist.org/packages/ianreid/switcher)[ RSS](/packages/ianreid-switcher/feed)WikiDiscussions v2 Synced 1w ago

READMEChangelog (10)Dependencies (6)Versions (13)Used By (2)

[![AWS Image Handler URLs icon](./src/icon.svg)](./src/icon.svg)

Switcher for Craft CMS
======================

[](#switcher-for-craft-cms)

Requirements
------------

[](#requirements)

This plugin requires Craft CMS ^4.x or ^5.x

Installation
------------

[](#installation)

To install the plugin, follow these instructions.

1. In your terminal, go to your Craft project:

    ```
     cd /path/to/project

    ```
2. Then tell Composer to load the plugin:

    ```
     composer require ianreid/switcher -w && php craft plugin/install switcher

    ```

Overview
--------

[](#overview)

The Switcher plugin for Craft CMS provides a Twig function for generating a site switcher on your webpage. This switcher can be configured to display sites from the current group or all groups.

Twig function
-------------

[](#twig-function)

The `getSwitcherSites()` Twig function comes with several parameters.

### getSwitcherSites()

[](#getswitchersites)

ParametersTypeDefaultDescriptionsourceElement or ArraynullElement or array from which the sites are extracted.removeCurrentBooltrueDetermines whether the current site should be excluded from the output.onlyCurrentGroupBooltrueSpecifies whether only sites from the current group should be shown.redirectHomeIfMissingBoolfalseDecides whether to redirect to the home page if a site is missing.### Recommended usage

[](#recommended-usage)

We suggest setting the source on a per-template basis. You can establish a fallback to `entry`, which allows you to set the variable for elements like categories, products, or an array of custom routes.

##### 1. Define an availableSites variable in your main layout file

[](#1-define-an-availablesites-variable-in-your-main-layout-file)

`{% set availableSites = getSwitcherSites(switcherCustomSource|default(entry ?? null)) %}`

In this variable, we use the `switcherCustomSource` variable as the source, with `entry` as the fallback, and then `null`.

You can then pass this variable to your navbar or any file that includes a *site/languages* switcher to prevent a redundant query.

By defining an `availableSites` variable at the top of your main layout file, you can also use it for the `og:locale:alternate` meta in the head, the ``, etc.

##### 2. Determine your source in your page template

[](#2-determine-your-source-in-your-page-template)

For any `craft\base\Element` **other than `Entry`** (the default in the previous example), you can do the following in your page template :

```
{% set switcherCustomSource = product %}

```

or

```
{% set switcherCustomSource = category %}

```

or for an array (ex: with custom routes)

```
{% set switcherCustomSource = [
      {'uri':'cart', 'siteId': 1},
      {'uri':'panier', 'siteId': 2},
      {'uri':'cesta', 'siteId': 3},
   ]
%}

```

### Output

[](#output)

The function returns an array of items with two keys: "url" and "site". The "url" key is the site's URL, and the "site" key is the site model.

```
array [
  0 => array [
    "url" => "http://yoursite.com/uri"
    "site" => craft\models\Site {}
  ]
  1 => array [
    "url" => "http://yoursite.com/en/uri"
    "site" => craft\models\Site {}
  ]
]

```

Site Switcher Examples
----------------------

[](#site-switcher-examples)

##### Basic usage

[](#basic-usage)

```

{% if availableSites|length %}
   {% for item in availableSites %}

         {{ item.site.language }}

   {% endfor %}
{% endif %}

```

##### Grouping Sites by Groups

[](#grouping-sites-by-groups)

```

{% if availableSites|length %}

   {% set availableSitesByGroup = availableSites|group(lang => lang.site.group) %}

   {% for group, langs in availableSitesByGroup %}

      {{ group }}
      {% for item in langs %}

            {{ item.site.language }}

      {% endfor %}

   {% endfor %}
{% endif %}

```

##### Displaying Only the First Two Letters of the Language

[](#displaying-only-the-first-two-letters-of-the-language)

```
{% if availableSites|length %}
   {% for item in availableSites %}

         {{ item.site.language [0:2]|capitalize }}

   {% endfor %}
{% endif %}

```

##### Using for og:locale:alternate in ``

[](#using-for-oglocalealternate-in-head)

Use your previously created `availableSites` variable if you wish to apply the same parameters, or create a different variable if not.

💡 You must define your variable **PRIOR** to the following meta property.

```

{% if availableSites|length %}
   {% for item in availableSites %}

   {% endfor %}
{% endif %}

```

> 💡 All these examples can be adjusted based on the function parameters.

---

This plugin is brought to you by [Ian Reid Langevin](https://www.reidlangevin.com)

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance77

Regular maintenance activity

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~101 days

Recently: every ~175 days

Total

12

Last Release

127d ago

Major Versions

v1.x-dev → 2.0.02026-04-03

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/85630027?v=4)[Ian Reid Langevin](/maintainers/ianreidlangevin)[@ianreidlangevin](https://github.com/ianreidlangevin)

---

Top Contributors

[![ianreidlangevin](https://avatars.githubusercontent.com/u/85630027?v=4)](https://github.com/ianreidlangevin "ianreidlangevin (22 commits)")

---

Tags

localizationlanguagecmslocaleCraftcraftcmscraft-pluginsitelanguage-switcher

### Embed Badge

![Health badge](/badges/ianreid-switcher/health.svg)

```
[![Health](https://phpackages.com/badges/ianreid-switcher/health.svg)](https://phpackages.com/packages/ianreid-switcher)
```

###  Alternatives

[verbb/formie

The most user-friendly forms plugin for Craft.

101400.6k76](/packages/verbb-formie)[acclaro/translations

Easily launch and manage multilingual Craft websites without having to copy/paste content or manually track updates.

1329.6k](/packages/acclaro-translations)[verbb/hyper

A user-friendly links field for Craft.

24153.5k14](/packages/verbb-hyper)[verbb/vizy

A flexible visual editor field for Craft.

4251.5k1](/packages/verbb-vizy)[verbb/events

A full-featured plugin for event management and ticketing.

2312.1k](/packages/verbb-events)[verbb/icon-picker

A slick field to pick icons from. Supports SVGs, Sprites, Webfonts, Font Awesome and more.

16172.7k7](/packages/verbb-icon-picker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
