Download the PHP package ianreid/switcher without Composer

On this page you can find all versions of the php package ianreid/switcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package switcher

Switcher for Craft CMS

Requirements

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

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

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

The getSwitcherSites() Twig function comes with several parameters.

getSwitcherSites()

Parameters Type Default Description
source Element or Array null Element or array from which the sites are extracted.
removeCurrent Bool true Determines whether the current site should be excluded from the output.
onlyCurrentGroup Bool true Specifies whether only sites from the current group should be shown.
redirectHomeIfMissing Bool false Decides whether to redirect to the home page if a site is missing.

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

{% 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 <link rel=alternate>, etc.

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 :

or

or for an array (ex: with custom routes)

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.

Site Switcher Examples

Basic usage
Grouping Sites by Groups
Displaying Only the First Two Letters of the Language
Using for og:locale:alternate in <head>

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

:bulb: You must define your variable PRIOR to the following meta property.

:bulb: All these examples can be adjusted based on the function parameters.


This plugin is brought to you by Ian Reid Langevin


All versions of switcher with dependencies

PHP Build Version
Package Version
Requires craftcms/cms Version ^3.0|^4.0|^5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ianreid/switcher contains the following files

Loading the files please wait ....