Jump to content

[Question] How to refresh a TPL block after AJAX call


Recommended Posts

Hi guys,

I have a problem with my product page: if I choose a combination of the product the reference code doesn't refresh.

Now I think that the problem is with my block code in the template file.

I found the method displayAjaxRefresh in ProductController.php where other blocks are "refreshed" with Ajax Die.

I want to update my block too but it doesn't work.

Where do I have to implement the "refreshing" logic?

Thank you in advance.

Info:

Prestashop version: 1.7

// In my TPL file I have something like this

{block name='my_block_name'}
	{include file="path/to/tpl-file.tpl" data=$some_data}
{/block}

// In ProductController.php I added

$this->ajaxDie(Tools::jsonEncode(array(
	...
    'my_block_name' => $this->render(
    	'path/to/tpl-file.tpl',
        array(
        	'data' => 'Updated data',
        )
    ),
	...
));

// I see the correct AJAX response in my network tab

 

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