0

I have 4 level product categories. For the menu I am building I need to pick a second category in all top level categories

So I get top level categories like so

{% set lv1Categories  = craft.categories.group('products').level(1) %}

How do I then get a second in the returned list?

{% set cat = lv1Categories[1] %}

This doesn't seem to work

4
  • Hey, what do you expect lv1Categories[1] to do? Do you want a 2nd level subcategory?
    – Johannes
    Jan 15 at 19:47
  • Might help to post a screen cap of your category structure? Jan 15 at 19:52
  • @Johannes There are two top level categories 'Recipients' and 'Departments'. I would expect lv1Categories[1] to reference 'Departments', so I can iterate over it's children with {% for categoryLv2 in categoryLv1.getChildren() %}
    – Lumiere
    Jan 15 at 20:26
  • If that's your actual markup, then the first line is missing a .all() - without it, you have a CategoryQuery object rather than an iterable set of results. Jan 18 at 8:36

Your Answer

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

Browse other questions tagged or ask your own question.