I have a categories field on an entry that can have one or many children. I am able to output everything - but would like to restrict the field a bit more.
If a child has been selected, I do not want to show the parent. In my example, I only want to show "child".
It is possible, that I might only choose "parent" and I only want that to show. Or, is there a different way I should go about doing this? Thank you for any suggestions!
I've tried something like this:
{% for service in entry.servies %}
{% set subCategories = craft.categories.descendantOf(service) %}
{% if subCategories|length %}
...
{% endif %}
{% endfor %}
But that will show the child category if it's selected or not. I would only like to show the "Child" category if it was actually selected. Otherwise, show the "parent" category.
UPDATE/SOLUTION
First, I want to thank Robin for your help. I tried different variations and was unsuccessful. I ended up taking my existing category and making it a structure. This gave me the flexibility that I needed.
level
and select the first? That way it might be possible to select only the deepest entry (child). Btw: if this is for Craft 3 keep in mind looping through queries is deprecated