User tests: Successful: Unsuccessful:
In current state the developers add the script options as global variables via addScriptDeclaration, that can be not always safe, and not nice. This path allow to store options in the one global object, where the options separated by the extension name.
The options stays as array until header render, that allow to simple overwrite it if need.
Example add the script option:
$options = array(
'showAlert' => false,
'consolelog' => true,
'text' => 'Hi! I am "Text"!',
'someArray' => array('one', 'two', 'and so on')
);
$doc->setScriptOptions($options, 'plg_examplejs');
Access to the options in frontend:
Joomla.optionsStorage.plg_examplejs;
Links:
I meant you're missing P: _scripts_oPtions
Your are right about JSON_FORCE_OBJECT. I just copied that from my code :)
ah hahaha
I thought you mean scriptsoptions ...
thanks! really not seen :)
now should be better ;)
nice tip, need to try...
what with a typo you mean? for me looks good :)
about JSON_FORCE_OBJECT I think it no need cause it convert the non-associative array to object that not really nice in case when you need to have the array in the options