{"id":13396037,"url":"https://github.com/spatie/laravel-blade-javascript","last_synced_at":"2025-05-14T03:12:01.663Z","repository":{"id":8834760,"uuid":"59886128","full_name":"spatie/laravel-blade-javascript","owner":"spatie","description":"A Blade directive to export variables to JavaScript","archived":false,"fork":false,"pushed_at":"2025-02-06T11:54:07.000Z","size":118,"stargazers_count":620,"open_issues_count":0,"forks_count":40,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-05-10T19:12:44.929Z","etag":null,"topics":["api","blade","javascript","laravel","php","view"],"latest_commit_sha":null,"homepage":"https://freek.dev/486-a-blade-directive-to-export-php-variables-to-javascript","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://spatie.be/open-source/support-us"}},"created_at":"2016-05-28T09:01:52.000Z","updated_at":"2025-04-11T02:26:17.000Z","dependencies_parsed_at":"2023-11-14T15:29:57.490Z","dependency_job_id":"87ac51df-cbcf-4e09-8225-511f5485c55a","html_url":"https://github.com/spatie/laravel-blade-javascript","commit_stats":{"total_commits":118,"total_committers":26,"mean_commits":4.538461538461538,"dds":"0.47457627118644063","last_synced_commit":"50934f500f60da70400eba1bda6ceda0a56afec3"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-blade-javascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-blade-javascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-blade-javascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-blade-javascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-blade-javascript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254059521,"owners_count":22007771,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","blade","javascript","laravel","php","view"],"created_at":"2024-07-30T18:00:38.156Z","updated_at":"2025-05-14T03:11:56.645Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://spatie.be/open-source/support-us"],"categories":["Popular Packages","Paquetes utiles"],"sub_categories":[],"readme":"# A Blade directive to export variables to JavaScript\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-blade-javascript.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-blade-javascript)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![run-tests](https://github.com/spatie/laravel-blade-javascript/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-blade-javascript/actions/workflows/run-tests.yml)\n![Check \u0026 fix styling](https://github.com/spatie/laravel-blade-javascript/workflows/Check%20\u0026%20fix%20styling/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-blade-javascript.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-blade-javascript)\n\nThis package contains a Blade directive to export values to JavaScript.\n\nHere's an example of how it can be used:\n\n```php\n@javascript('key', 'value')\n```\n\nThe rendered view will output:\n```html\n\u003cscript\u003ewindow['key'] = 'value';\u003c/script\u003e\n```\n\nSo in your browser you now have access to a key variable:\n```js\nconsole.log(key); //outputs \"value\"\n```\n\nSpatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-blade-javascript.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-blade-javascript)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n``` bash\ncomposer require spatie/laravel-blade-javascript\n```\n\nThe package will automatically register itself.\n\nOptionally the config file can be published with\n\n```bash\nphp artisan vendor:publish --provider=\"Spatie\\BladeJavaScript\\BladeJavaScriptServiceProvider\" --tag=\"config\"\n```\n\nThis is the contents of the published config file:\n\n```php\nreturn [\n\n    /**\n     * All passed values will be present in this JavaScript namespace. Set this to an empty string\n     * to use the window object.\n     */\n    'namespace' =\u003e '',\n];\n```\n\nIf you want to customize the generated `\u003cscript\u003e` tag you can publish and override the used view.\n\n```bash\nphp artisan vendor:publish --provider=\"Spatie\\BladeJavaScript\\BladeJavaScriptServiceProvider\" --tag=\"views\"\n```\n\nAfter this you can edit the published view `resources/views/vendor/bladeJavaScript/index.blade.php`. This is usefull to add the `type` or a CSP `nonce`.\n\n## Usage\n\nWith the package installed you can make use of a `@javascript` Blade directive.\n\n```php\n@javascript('key', 'value')\n```\n\nThe rendered view will output:\n```html\n\u003cscript\u003ekey = 'value';\u003c/script\u003e\n```\n\nYou can also use a single argument:\n```php\n@javascript(['key' =\u003e 'value'])\n```\n\nThis will also output:\n```html\n\u003cscript\u003ekey = 'value';\u003c/script\u003e\n```\n\nWhen setting the namespace to eg `js` in the config file this will be the output:\n\n```html\n\u003cscript\u003ewindow['js'] = window['js'] || {};js['key'] = 'value';\u003c/script\u003e\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Testing\n\n``` bash\ncomposer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security\n\nIf you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [Sebastian De Deyne](https://github.com/seb)\n- [All Contributors](../../contributors)\n\nThis repository contains some code from the [laracasts/PHP-Vars-To-Js-Transformer](https://github.com/laracasts/PHP-Vars-To-Js-Transformer) package written by [Jeffrey Way](https://github.com/JeffreyWay).\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-blade-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-blade-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-blade-javascript/lists"}