1

Just thinking of an easy way for the user to manage products on a site.

Therefore is it possible to display entries by a category and a lightswitch toggle?

IE. Category selected is Photocopiers and Lightswitch is color?

Then check for those and display the entries? Stuck on the syntax:

{% set category = craft.categories.slug('copier') %}
{% set colortype = craft.entries().section('products').color(true).all() %}
{% set entries = craft.entries.section('products').relatedTo(category).find() 

*Stuck on the syntax here to add to the query the lightswitch field*

 %}




    {# If there are any entries, loop through them #}
    {% if entries | length %}

        {# For each entry we find, do this #}
        {% for entry in entries %}
            <p>{{ entry.title }}</p>
        {% endfor %}

{% endif %}

TIA :)

2

You can add the lightswitch filter to the entries query like so:

{% set category = craft.categories.slug('copier') %}
{% set entries = craft.entries()
                      .section('products')
                      .relatedTo(category)
                      .color(true)
                      .all() %}

{# If there are any entries, loop through them #}
{% if entries | length %}

    {# For each entry we find, do this #}
    {% for entry in entries %}
        <p>{{ entry.title }}</p>
    {% endfor %}

{% endif %}
  • Awesome, thank you very much for your help. – moondawg Sep 17 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.