Categories Side Menu - sub items

  • I think it'd be a tricky template to recreate in any language, twig included. I think going down the each route is slower in terms of performance and going down 4 levels would get messy.


    I do think it's doable with a template, but I can't dedicate enough time to solve it easily. There will be a way to do it in Perch, it's just working out the best way and something that's clean in implementation.

  • Hello dazglaser


    You can expand your original solution for the 2 levels and make it more dynamic to handle any number of levels:



    Note I'm using a function get_sub_categories() inside the each option. This allows you to handle things more dynamically. If you really need separate templates:



    If you only need to apply a different CSS class based on the level, you can remove the first bit of the function and rely on conditional tags inside the template:




    All your templates would need to have the following to display the subitems:


    HTML
    1. <perch:category id="subitems" html>
  • Hi,


    If you change the name of the default category:


    1. // default template
    2. $template = 'categorylevel_1.html';

    it doesn't actually use that template, it only uses category.html for level 1.


    If I then put my level 1 code into category.html it breaks the actual category system in Perch CMS.


    Does that make sense?


    I'm just trying to specify another template for level 1 other than the default category.html

  • That's the default category for the sub-levels (it's inside a function called get_sub_categories()). Apologies if my comment caused some confusion.


    The first level is output by the initial perch_categories() call: