Jump to content

Listing products by category in header


Recommended Posts

Hi,

 

I'm new to Prestashop and struggling since a couple of days with a basic task... I just would like to list the products of each category into my header (header.tpl).
I don't know how to do it.

I know how to list products :

{if $listing.products|count}
  {block name='product_list'}
    {include file='catalog/_partials/products.tpl' listing=$listing}
  {/block}
{else}
  {include file='errors/not-found.tpl'}
{/if}

But I don't know how to set up a category to this listing.

Please can you help me ? Thanks a lot !
NB. I'm using Prestashop 1.7.4

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

You need to assign the variable from the controller first, it's not available in the header by default. Have a look at initContent in the FrontController class. Get all categories, then all products for them, and assign to the template. This way the list will be available in all pages

Link to comment
Share on other sites

  • 2 weeks later...
On 12/08/2018 at 2:30 AM, NemoPS said:

You need to assign the variable from the controller first, it's not available in the header by default. Have a look at initContent in the FrontController class. Get all categories, then all products for them, and assign to the template. This way the list will be available in all pages

First of all, thank you very much for your answer.

Despite my inexperience to Prestashop, I tried to go ahead on your track.

- I've created a 'buildmenu' module (/modules/buildmenu/)
- A 'custom.php' file into '/modules/buildmenu/controllers/front/'
- A 'buildmenu.tpl' file into '/modules/buildmenu/views/templates/front/'

Here is the code in my 'custom.php' file : 

<?php
class BuildMenu extends ModuleFrontController {
  public function initContent() {
    $this->context->smarty->assign(array(
      'hello' => 'Hello World!!!',
    ));
    $this->setTemplate('buildmenu.tpl');
  }
}
?>


Now I don't know :

- how to get all categories and all products
- how to display it on my main template (/themes/mytheme/templates/_partials/header.tpl)

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