Jump to content

Load jQuery with parameters Product Page PrestaShop 1.7


Recommended Posts

Hello everyone, I am developing a functionality for the product page with a module in prestashop 1.7.x, 1.6.x and 1.5, and depending on the client configuration will load a jQuery with parameters that can change, I need to load a jQuery with different variables.
 
Now I'm loading it in-line at the hookdisplayFooterProduct() but the prestashop loads the jQuery file after the body tag, so I have the "jQuery is not defined" error, how can I load the inline javascript by passing parameters to it?.
 
 
module hook register function
public function hookdisplayFooterProduct($params)
    {
        ...variables assignation...


        $this->smarty->assign(array(
                                    ...variables to send to inline javascript...
                                    ));

        return $this->display(__FILE__, 'jquery_inline_tpl.tpl');
    }

Inline javascript "jquery_inline_tpl.tpl"

{literal}
<script type="text/javascript">


	jQuery(document).ready(function(){

		...There I get the variables but this not load because...
                ...jQuery is not defined, couse it is at productFooter...
		...And jquery is loaded after it...

	});
</script>
{/literal}
 
Regards, and thank you very much.
Link to comment
Share on other sites

Hi...

First you need to define all js variable in template file and after use the the your js file.you can use hookHeader() for this

Like as

public function hookHeader()
{
     $this->context->smarty->assign(array(
         'your_varible' => $your_varible,
    ));
    return $this->context->smarty->fetch(your_path-template_file....'/hookHeader.tpl');//Here is example file "hookHeader.tpl"
} 

Now you can assign your  varible is "hookHeader.tpl" file
 

<script type="text/javascript">
var your_varible = "{$your_varible|escape:'html':'UTF-8'}";
</script>

now you can use js "your_varible" is your js file

Thanks

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hi...

 

First you need to define all js variable in template file and after use the the your js file.you can use hookHeader() for this

 

Like as

public function hookHeader()
{
     $this->context->smarty->assign(array(
         'your_varible' => $your_varible,
    ));
    return $this->context->smarty->fetch(your_path-template_file....'/hookHeader.tpl');//Here is example file "hookHeader.tpl"
} 

Now you can assign your  varible is "hookHeader.tpl" file

 

<script type="text/javascript">
var your_varible = "{$your_varible|escape:'html':'UTF-8'}";
</script>

now you can use js "your_varible" is your js file

 

Thanks

 

 

Thank u, you save me.

 

Grettings.

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