Skip to content

Extend HeadScript to pass window.APP props #94

@bravadomizzou

Description

@bravadomizzou

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>

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions