Skip to content

Conversation

@tariq86
Copy link

@tariq86 tariq86 commented Nov 30, 2018

In certain cases, a user of this package might need to add one or more HTML attributes to the <script> tag outputted in the compiled view file. For example, if CSP headers are set up for the site, you need to add nonces to inline <script> tags so that the browser allows them to execute.

This is achieved by adding a new function to the ViewBinder and Transformer classes: setHtmlAttributes(array $attributes).

If this method is called, the ViewBinder->bind() method will include the attributes that were given to the setHtmlAttributes function.

For example:

\JavaScript::setHtmlAttributes(['foo' => 'bar']);
\JavaScript::put(['fizz' => 'buzz']);

Will result in the following output in the HTML file:

<script foo="bar">
   JS.fizz = "buzz";
</script>

@LiamBull
Copy link

LiamBull commented Jun 5, 2019

Would love to see this implemented, as it would save me refactoring out this package from my project.

@tariq86
Copy link
Author

tariq86 commented Jun 12, 2019

@LiamBull I have these changes published in my clone, you can point at that until this repo is updated:

  1. Add the repo to your composer.json's "repositories" section:
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/tariq86/PHP-Vars-To-Js-Transformer"
        }
    ]
  1. Update package laracasts/utilities to version 4.0.0

The code is available here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants