Search code examples
phpsmartycs-cart

CS-Cart category image in menu


In CS-Cart on a categories page you get a list of subcategories with images if one has been uploaded.

How can I get the category image to also show in the main menu (topmenu_dropdown.tpl)?

I have tried using something like:

{include file="common/image.tpl" images=$item2.main_pair image_width=150}

but it looks like the image is not being made available to topmenu_dropdown.tpl


Solution

  • Finally found the answer to this so will post for others that may need it.

    This is possible using the very useful fn_get_category_data which enables you to get data from a category.

    In the topmenu_dropdown.tpl you first need to find the category ID. While this is not directly available, you can get it off the end of the href variable. (This is only possible if it is an auto generated category menu)

    {assign var=catid value="="|explode:$item2.href}
    

    This will make an array by splitting href at the = sign.

    {$category_data = $catid.1|fn_get_category_data}
    

    Then you can use the id number to get the correct category data.

    Now $category_data will have all the variables you want including the desired image using $category_data.main_pair