Jump to content

get category by id and sub categories and show under another category page


Abdul

Recommended Posts

Hi, i am new to prestashop and using prestashop 1.7. 

I wanna show one parent category with its sub categories data/information into another parent category page in category.tpl file.

I have created frontcontroller
 

public static function getCategoryName($id){

$category = new Category ($id,Context::getContext()->language->id);

return $category->name;

}

and displaying category name by id 

{FrontController::getCategoryName(273)}

273 is category id.

now i can not find the way to show sub categories and their cover images of category id 273

 

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

To display the same in .tpl file, you need to assign the variable from the controller file. This function can't be called directly into tpl.

In the controller, write the code like.

$subcategories = getChildren(273, Context::getContext()->language->id);

$this->conext->smarty->assign('subcategories', $subcategories);

In the tpl file, you can access the subcategories using the variable {$subcategories} but you need to run a loop in the tpl to display the subcategories. 

 

 

  • Like 1
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...