Jump to content

Display category name with selected depth


JoZu

Recommended Posts

I use this code in the product.tpl file to show product categories:
 

{foreach from=Product::getProductCategoriesFull($product.id_product) item=cat}
                
    <a href="{$link->getCategoryLink({$cat.id_category})}" title="{$cat.name}">{$cat.name}</a>, 
   
{/foreach}

 

The result is similar to this: Name: Lifts, Machines, Gearless,

The question is: How can I choose what element depth I want to show (Lifts only, Machines only or Gearless only)??

I need to show one element from the foreach element position (category depth)

Thanks.

Link to comment
Share on other sites

@JoZu

The category value return only id and value it return no depth the function which you used. You can do other way assign a variable and increase the value , depending on the variable value you can show category

 

{counter start=1 print=false assign="count"}
{foreach from=Product::getProductCategoriesFull($product.id_product) item=cat}
    <a href="{$link->getCategoryLink({$cat.id_category})}" title="{$cat.name}">{$cat.name}</a>, 
     {counter}
{/foreach}

 

then you can do like this

{if $count === 1} <p>Count is 1</p> {/if}

 

Hope this will help you

Thank you

Link to comment
Share on other sites

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...