I'm using channel:categories and would like to show only child categories so I added the following conditional {if {parent_id} != 0}...{/if} but get php errors as soon as I add it to the template. I tried any sort of variable check {category_description} and get errors.

The above conditional was taken from an accepted answer on another thread.

Parse error: syntax error, unexpected '{' in path\to\system\expressionengine\libraries\Functions.php(689) : eval()'d code on line 43

My template looks like this:

{!--stash 1st level category list--}
{exp:stash:set name="categories" parse_tags="yes"}{exp:gwcode_categories channel="products" depth="1" style="linear" backspace="1"}{cat_url_title}|{/exp:gwcode_categories}{/exp:stash:set}

{!--category ids for sub cats--}
{exp:stash:set name="sub_category_ids" parse_tags="yes"}{exp:gwcode_categories channel="products" output_depth="2" style="linear" backspace="1" cat_url_title="{segment_3}"}{cat_id}|{/exp:gwcode_categories}{/exp:stash:set}

{exp:switchee variable="{segment_2}" parse="inward"}
  {case value="#^P(/d+)$#|category|''"}

    {switchee variable="{segment_3}" parse="inward"}

      {case value="{stash:categories}"}{!--level 1 category listing filtered by stashed list --}

        {exp:low_variables:single var="lv-products-cat-tier1" 

      {/case}{!--level 1 category listing--}

        some more case checks here

    {/switchee}{!--end nested switchee--}

{/case}{!--listing & category listing--}

some more case checks here

Finally my lv-products-cat-tier1 is a low variable with the following code where the parent conditional will wrapp the double-square div when it is working:

        {!--list sub categories--}
        {exp:channel:categories channel="products" show="{pre_single_cat_id}|{pre_seg_id}" style="linear"}

{if {parent_id} != 0}

        <div class="col-xs-6 double-square">
            <img src="http://lorempixel.com/545/270/people" alt="" class="img-responsive">
            <div class="row">
            <div class="pos-ab">
                <div class="col-xs-6 left">
                    <h4><a href="/products/category/{category_url_title}">{category_name}</a></h4>

                <div class="col-xs-6 right">
                  <div class="content">
                    {exp:eehive_hacksaw chars="" words="15" cutoff="" append="" allow="<p><b><a>"}
          </div><!--double square-->


1 Answer 1


The problem with that is that if {parent_id} doesn't get replaced with a number before the conditional is evaluated, then EE will choke because when converted to PHP it becomes:

if ({parent_id} == 0)

Either this

{if parent_id != 0}

Or this

{if "{parent_id}" != "0"}

Is more fault tolerant when the variable doesn't exist.

But, you may wonder, why is your conditional getting parsed before {parent_id} has been replaced in the first place? Because by default {exp:stash:parse} parses conditionals after it has parsed the layers of tags it wraps to a "depth" of 3 (parse_conditionals="yes" and parse_depth="3" by default).

It so happens that in your code the {exp:low_variables} tag is on the deepest layer to be parsed (layer 3). This tag gets replaced with your {exp:channel:categories} tag pair which is NOT parsed, because at this point Stash is done parsing and will now parse any conditionals that have been exposed. See the problem?

To stop this undesirable behaviour you can either set parse_conditionals="no" on the {exp:stash:parse} tag or increase the parse depth with parse_depth="4" so that the categories tag is fully parsed before the conditionals are evaluated.

  • That's a proper answer.
    – foamcow
    Commented Jun 12, 2014 at 8:55

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.