ufk ufk - 7 months ago 107
Smarty Question

using smarty template engine in registered javascript files with prestashop 1.7

I'm writing Prestashop module.

In that module when I want to register a javascript file I connect to the hook

and use
like so:


this loads the javascript properly but I can't use smarty template engine in those javascript files.

is there a way to do that ? :)

if not... should I just add all my javascript files inline ?


so I added this to my hook function:


and this my js file:

$(function() {
var options = {
data: tuxinmodcartype.car_companies,
list: {
match: {
enabled: true



and I get the error
ReferenceError: tuxinmodcartype is not defined

Answer Source

For accessing variables in javascript you can assign them in your controllers with:

    'mymodule' => array(
        'var1' => 'yes',
        'var2' => 'no'

Then you can use them in your javascript or through console:

let var1 = mymodule.var1;
let var2 = mymodule.var2;

Building javascript files with smarty... I guess it's better to split javascript into more files and load them through controller based on conditions. Or use the above definition for variables to control execution path in your javascript.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download