Jump to content

Assign a var to show in product-list.tpl


Recommended Posts

Hi there!

I'm getting little crazy because I want to run a SQL in a controller and show the result in the frontend when all itema are listed (product-list.tpl).

 

I did something in ProductController.php (in public function initContent()) and I assigned the output with SMARTY and on product.tpl everything is fine

 

But I cannot understand where I have to assign the smarty variable to let the product-list.tpl give me some output

There is no Controllers loading the product-list.tpl with a setTemplate. That's CRAZY :-)

 

 

Please help, I'm soooo stucked :-s

 

Thanks!

Link to comment
Share on other sites

depends where in the front end, index, i.e. featured products etc it will be the module getting the products from the category and calling the product-list.tpl directly, it gets included directly from another template, from the category pages it uses the CategoryController.

 

It is a little inconsistent because anything via the CategoryController calls a few hooks where you can modify the list of products returned, from the homefeatured module, and other index page product lists, it doesn't call these hooks.

Link to comment
Share on other sites

If you need to use variable only on category page then check the below sample code

 

Go to category controller and initialize your variable in initContent() using below code

$this->context->smarty->assign('your_variable','$your_value');

 

Now open product-list.tpl and use below code to print values.

{if isset($your_value)}

{$your_variable}

{/if}

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