la-haute-societe / craft-locale-selector
A Craft field type for selecting a site or a country
Installs: 305
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Type:craft-plugin
Requires
- ext-intl: >=1.0.0
- craftcms/cms: ^4.0.0
- rinvex/countries: ^7.3
This package is auto-updated.
Last update: 2024-10-29 06:36:27 UTC
README
This plugin adds a new "Country or Site" field type to the Craft CMS. The Country or site field allows content editors to choose from a list of link types and offers individual input fields for each of them.
Requirements
This plugin requires Craft CMS 4.0.0 or later.
Installation
The plugin can be installed from the integrated plugin store by searching for "Locale selector" or using Composer:
- Open your terminal and navigate to your Craft project:
cd /path/to/project
- Then tell Composer to load the plugin:
composer require la-haute-societe/craft-locale-selector
- Finally, install and enable the plugin:
./craft plugin/install locale-selector ./craft plugin/enable locale-selector
Usage
After the plugin has been installed, "Country or site" fields can be created using the field settings within the control panel. All field settings can be found within the field manager.
Templating
Countries
Country fields can be rendered directly in Twig, they return the localized name of the selected country.
{{ entry.myCountryField }}
The field value is actually an instance of
\lhs\craft\localeSelectorField\models\CountryModel
which exposes additional
properties and methods that can be used in templates.
Sites
Site fields can be rendered directly in Twig, they return the name of the site.
{{ entry.mySiteField }}
The field value is actually an instance of \craft\models\Site
which exposes
additional properties and methods that can be used in templates.
GraphQL
GraphQL is supported 🎉
Sites
Sites expose the following properties:
id
-[string]
: The ID of the sitename
-[string]
: The name of the sitelanguage
-[string]
: The language code of the site as selected in the CP (example:fr-FR
oren
)baseUrl
-[string]
: The site base URLhandle
-[string]
: The site handle
Countries
Countries expose the following properties:
name
-[string]
: The localized name of the countrynativeName
-[string]
: The name of the country, in the country main languageiso2
-[string]
: The 2-letter country code, according to ISO 3166iso3
-[string]
: The 3-letter country code, according to ISO 3166
Roadmap
- Add the ability to select languages
- Add the ability to select locales (language + country)