https://github.com/codemonauts/craft3-sites-field
Craft 3 Field type that allows the selection of Craft sites.
https://github.com/codemonauts/craft3-sites-field
Last synced: 3 days ago
JSON representation
Craft 3 Field type that allows the selection of Craft sites.
- Host: GitHub
- URL: https://github.com/codemonauts/craft3-sites-field
- Owner: codemonauts
- License: mit
- Created: 2019-07-26T14:25:39.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-14T19:25:17.000Z (about 8 years ago)
- Last Synced: 2025-12-25T22:31:15.445Z (4 months ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 1
- Watchers: 0
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Sites Field for Craft 3
This plugin provides a field type for choosing sites. Entries using this field can then access the site ID in their templates.
---
## Requirements
* Craft CMS 3.0.0-RC1 or above
## Example Usage
To display only events related to the current site you could use the following logic:
```twig
{% set events = craft.entries.site('main').section('blog').type('event').orderBy('date asc').all() %}
{% for event in events %}
{% if craft.app.sites.currentSite.id in event.siteIds %}
{# show this event... #}
{% endif %}
{% endfor %}
```
> Note: `siteIds` returns an array of site ID's which you can use the twig [in](https://twig.symfony.com/doc/2.x/templates.html#containment-operator) operator.