-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
As a way to make passing data to the front end, I propose that we extend HeadScript so that we can assign values similar to the way we assign values for views. This prevents against having JS variable assignment littered throughout code and prevents against having a bunch of random global variables.
Notes:
Would need to be able to put it after/before other scripts??
Would need to modify the toString() and possibly other methods.
Possibly allow using other namespaces, not just APP
API examples
/**
@param string $property
@param mixed $value
@param bool|callable $escapeValue Disable current escaping or pass a callable to do custom escaping
*/
public function assign($property, $value, $escapeValue = true)
{
// store the given params to $this
}
This
$headScript->assign('settings', $settings);
$headScript->assign('user', $user);
$headScript->assign('data', $data);
translates to this when rendered
<script>
// @todo check for existance of that namespace 'APP', maybe merge it and console.warn() or console.error() (also check browser compatibility with console methods)
window.APP = {
"settings": {},
"user": {},
"data": {}
};
</script>
Reactions are currently unavailable