My goal is, passing a config variable from PHP to JavaScript. Registration of the script as usual.
$foo = $this->configModel->get('foo', 'bar');
// How to pass $foo to the script?
$this->hook->on('template:layout:js', array('template' => "plugins/Foobar/Assets/js/Foobar.js"));
Appending via “?foo=bar” doesn’t seem to work.
Maybe I’m searching too far. Is this possible at all?
im not 100% sure of your context, but you can pull the config value into, say a hidden form value, and then grab that value in js. it doesnt have to be a form, could be anything.
the other easy option is cookies.
if you show me code it might be easier for me to assist.
What you need to understand is that nginx will only forward the *.php file to the php interpreter, and the js file nginx will return it as a static resource file, so the php variable in the js file cannot be recognized without parsing, you can try use localstorage