Jump to content

PS_1.7.2 ps_categorytree - expand current category only


Duboe

Recommended Posts

The goal is quite simple: Only expand the current category.
 
Problem: I overwrite the module-file ps_categorytree.tpl in the theme.

{if $node.id==$category.id_parent || $node.id==$category.id} 

That works as is, but I ran into a problem. I have another module that adds an extra node at the end of the categories. 

 

Shop

  • Cat 1 + (signals that there are sub categories)
  • Cat 2 +
  • Cat 3
  • Cat from Module

 

When I click on the "Cat from Module" smarty breaks on the first +

 

Shop

  • Cat 1 (it breaks here because it has no an issue with $category.id_parent)

When I use an extra isset($category) in the if above it makes no difference and an isset($category.id_parent) throws an internal error...

 

Any suggestions?

Edited by Duboe (see edit history)
  • Like 1
Link to comment
Share on other sites

{if !$category->id && ($node.id==$category.id_parent || $node.id==$category.id)}

If anyone needs this - not the most elegant solution but it works. At least with one sub category.

 

A little more context: (If you don't know where to add this line)

 

If not already there create a folder named 'ps_categorytree' in your_theme -> modules folder. Now create the folders as follows 

views -> templates -> hook

 

Go to your root modules folder -> modules -> ps_categorytree follow the path above and copy the ps_categorytree.tpl into your created hook folder.

 

Now add / replace after {if $node.children} till {categories nodes=$node.children depth=$depth+1} (not included in the replace)

{if !$category->id && ($node.id==$category.id_parent || $node.id==$category.id)}
    <div class="navbar-toggler collapse-icons" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}" aria-expanded="true">
      <i class="material-icons add"></i>
      <i class="material-icons remove"></i>
    </div>

    <div class="collapse in" id="exCollapsingNavbar{$node.id}">

  {else}

    <div class="navbar-toggler collapse-icons" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}" aria-expanded="false">
      <i class="material-icons add"></i>
      <i class="material-icons remove"></i>
    </div>
    <div class="collapse" id="exCollapsingNavbar{$node.id}">
{/if}

and you are done. Parent categories should now expand if you are in a sub category.

Edited by Duboe (see edit history)
Link to comment
Share on other sites

  • 2 months later...

I have copied this code:

 

{if !$category->id && ($node.id==$category.id_parent || $node.id==$category.id)}

<div class="navbar-toggler collapse-icons" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}" aria-expanded="true">
<i class="material-icons add">xE145;</i>
<i class="material-icons remove">xE15B;</i>
</div>

<div class="collapse in" id="exCollapsingNavbar{$node.id}">

{else}

<div class="navbar-toggler collapse-icons" data-toggle="collapse" data-target="#exCollapsingNavbar{$node.id}" aria-expanded="false">
<i class="material-icons add">xE145;</i>
<i class="material-icons remove">xE15B;</i>
</div>
<div class="collapse" id="exCollapsingNavbar{$node.id}">
{/if

 

 

And paste it as they said. That is the only change I've made. 

 

What can I do about this? 

 

Thank you! 

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...