Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HTML Attributes on <script> Tag #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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