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 :)

1 Answer 1

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 %}
1
  • Awesome, thank you very much for your help.
    – moondawg
    Sep 17, 2019 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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