2017 © Pedro Peláez
 

craft-plugin fallback-site

Allows sites of a multi-site install to use entries of other sites if a matching slug is found.

image

charliedev/fallback-site

Allows sites of a multi-site install to use entries of other sites if a matching slug is found.

  • Tuesday, June 26, 2018
  • by charliedev
  • Repository
  • 2 Watchers
  • 11 Stars
  • 130 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 41 % Grown

The README.md

Fallback Site for Craft 3

This plugin allows each site to fall back to another site when a requested element cannot be found. This allows multi-site installations (typically for multiple languages) to gracefully fall back to existing content if available., (*1)

When a request is made for an element that would normally not be found, Fallback Site will check the configured site for an element with the same slug. For example, if you have an English site and a Spanish site as part of your craft install, and English is the fallback for Spanish, then handling for a request to the Spanish site would go as follows:, (*2)

  • First, if an element was found on the Spanish site, everything continues as normal, and Fallback Site does not intervene.
  • If an element was not found on the Spanish site, Fallback Site checks if there is an English element with the same the slug.
  • If an English element is found, then that element's ID is used to see if there is a Spanish version available, which can happen if an incorrect, untranslated slug is used.
    • If a Spanish version exists, then a 301 redirect will be sent to the user, directing them to the correct URL.
    • If a Spanish version does not exist, then Fallback Site makes Craft use the English element in place of the Spanish one (With some conditions listed below).
  • If an English element is not found, then the request continues as a 404 as normal.

See the flowcharts below which demonstrate what happens when requesting a page, about-us, under a secondary, Spanish site (located at /es) within a multi-site Craft installation., (*3)

Normal Craft element handling, (*4)

Craft routing without Fallback Site, (*5)

Element handling with Fallback Site, (*6)

Craft routing with Fallback Site, (*7)

Requirements

  • Craft CMS 3.0.0-RC1 or above

  1. Open a terminal and navigate to your project folder:
cd /path/to/project
  1. Require the package to download it via Composer:
composer require charliedev/fallback-site
  1. Install the plugin on the Settings -> Plugins page in the Craft control panel.

--- or ---, (*8)

  1. Install the plugin via the command line:
./craft install/plugin fallback-site

Configuration

Fallback Site settings panel, (*9)

Within the Craft control panel, go to the Settings -> Plugins page, and then look for the Settings button listed by the Fallback Site plugin., (*10)

Here, you can select which site acts as a fallback for each other site. Fallbacks can also be chained across multiple sites, each site falling back to the next., (*11)

Usage

While the plugin works without any additional configuration, you may want to know if an entry being displayed has been substituted by Fallback Site. This may be done to display notices about the availability of site-specific content, or notify users of the replacement. Detecting this can be done by comparing the current site stored by Craft with the entry's associated site., (*12)

{% if craft.app.sites.currentSite != entry.site %}
    {# Entry content is coming from a different site. #}
{% endif %}
{# ... or ... #}
{% if craft.app.language != entry.site.language %}
    {# Entry content is in a different language. #}
{% endif %}

Built for Craft CMS by Charlie Development, (*13)

The Versions

26/06 2018

dev-master

9999999-dev

Allows sites of a multi-site install to use entries of other sites if a matching slug is found.

  Sources   Download

MIT proprietary

The Requires

 

cms default element site craftcms craft fallback multi-site

26/06 2018

1.2.0

1.2.0.0

Allows sites of a multi-site install to use entries of other sites if a matching slug is found.

  Sources   Download

proprietary

The Requires

 

cms default element site craftcms craft fallback multi-site

26/02 2018

1.1.0

1.1.0.0

Allows sites of a multi-site install to use entries of other sites if a matching slug is found.

  Sources   Download

MIT

The Requires

 

cms default element site craftcms craft fallback multi-site

22/01 2018

1.0.0

1.0.0.0

Allows sites of a multi-site install to use entries of other sites if a matching slug is found.

  Sources   Download

MIT

The Requires

 

cms default element site craftcms craft fallback multi-site