How to target all Categories with parent ID == '#'

TradingboTradingbo Posts: 20Member

Hi everyone,

Relatively new to LS and trying to get my head around something.

How to target all sub-categories within a parent category within a given template.

I'm trying to achieve something akin to this:

{% if category.textpage and parent.category_id == '8661854' } 

<script type="text/javascript">

// do something

</script>

{% endif %}


The only reference I can find to parent categories in the documentation is:

categories.{{ category.id }}.parent

Presumably this only returns the parent of a specific category however. Also slightly unsure how to express the ID in this statement as:

{{categories.{{ '8661854' }}.parent}}

Returns a fatal error due to the two sets of curly brackets.

If anyone could point me in the right direction here would be amazing.

Many Thanks,

Best Answers

Answers

  • TradingboTradingbo Posts: 20Member
    edited May 4

    Hi Miles,

    Thanks, that's exactly almost what I was looking for.

    Just to clarify the syntax?

    In the rain documentation this is expressed as :

    shop.categories.{{ category.id }}.subs
    

    So is how you've written this above, actually the correct way?

    shop.categories[8661854].subs
    

    E.g. Square brackets, no quotes around ID or full stop before ID...

    Thanks,

    Post edited by Tradingbo on
  • TradingboTradingbo Posts: 20Member

    Hi Miles,

    Great explanation, appreciate the support!

    Thanks

Sign In or Register to comment.