Giter VIP home page Giter VIP logo

propagated-sites-field-plugin's Introduction

Sites Field for Craft 3

This plugin provides a field type for choosing craft sites. Entries using this field can then access the site ID in templates, for example for filtering. The entries are propagated to the selected sites only.

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:

{% 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 operator.

Installation

  • Over Craft Plugin Store

OR

"repositories": [
    ...
    {
        "type": "path",
        "url": "/path-to-repo/propagated-sites-field"
    }
]
  • Install plugin via composer
composer require furbo/propagated-sites-field
  • Plugin über Backend aktivieren
  • Create field from Type Sites (in the current release fieldhandle must be "sites")
  • Add Field to entries and save

Show field in frontend

If the entry is saved in frontend, the same propagtion logix apears

<label>Event Regions</label>
{% set currentsite = craft.app.fields.getFieldByHandle('sites') %}
{% set sites = craft.app.sites.getAllSites() %}
<input type="hidden" id="fields-sites" name="fields[sites][]" value="{{ currentSite.id }}">
	<br />
	{% for site in sites %}

        {% set checked = true ? 'checked=""' : '' %}
        <div>
            <input type="checkbox" value="{{site.id}}" class="checkbox" id="fields-sites-{{site.id}}" name="fields[sites][]" {{checked}}>
            <label for="fields-sites-{{site.id}}">{{site.name}}</label>
        </div>

    {% endfor %}
</div>

propagated-sites-field-plugin's People

Contributors

tonioseiler avatar

Stargazers

Brian Hanson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.