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

TradingboTradingbo Member Posts: 36

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


{% endif %}

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

categories.{{ }}.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


  • TradingboTradingbo Member Posts: 36
    edited May 2019

    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.{{ }}.subs

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


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


    Post edited by Tradingbo on
  • TradingboTradingbo Member Posts: 36

    Hi Miles,

    Great explanation, appreciate the support!


Sign In or Register to comment.