Acces to parent category values

  • I have a category called "location". A location can be California and one of its children is Los Angeles. I want to show the full direction of Los Angeles (Los Angeles, California) and that's my code but it's not working:


    Code
    1. <!-- Child location -->
    2. <perch:categories id="my_location" set="location">
    3. <perch:category id="catTitle" />
    4. </perch:categories>
    5. <!-- Parent location -->
    6. <perch:categories id="my_location" set="location" scope-parent="true">
    7.     <perch:category id="parent.catTitle" />
    8. </perch:categories>
  • drewm

    Approved the thread.
  • Hello Aleix,


    <perch:categories></perch:categories> has its own scope. Consider the following template:


    HTML
    1. <perch:content id="heading" type="text">
    2. <perch:categories id="my_location" set="location">
    3. <perch:category id="catTitle">
    4. <!--* you cannot access the field 'heading' in this scope *-->
    5. </perch:categories>


    You can't access the fields from the outer scope by default. In order to access the fields from the outer scope, you can use the scope-parent attribute:


    HTML
    1. <perch:content id="heading" type="text">
    2. <perch:categories id="my_location" set="location" scope-parent>
    3. <perch:category id="catTitle">
    4. <!--* you can now access the field 'heading' in this scope *-->
    5. <perch:category id="parent.heading" type="text">
    6. </perch:categories>


    So the scope-parent does not allow you to access a parent category and it is not the appropriate solution for your use-case.



    The closest thing to what you want as far as I know is catDisplayPath:


    HTML
    1. <perch:categories id="my_location" set="location">
    2. <perch:category id="catDisplayPath">
    3. </perch:categories>


    This would output "California › Los Angeles".