2017 © Pedro Peláez
 

library laravel-blade-javascript

A Blade directive to export variables to JavaScript

image

spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  • Tuesday, June 19, 2018
  • by Spatie
  • Repository
  • 13 Watchers
  • 314 Stars
  • 72,952 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 29 Forks
  • 0 Open issues
  • 18 Versions
  • 12 % Grown

The README.md

A Blade directive to export variables to JavaScript

Latest Version on Packagist Software License run-tests Check & fix styling Total Downloads, (*1)

This package contains a Blade directive to export values to JavaScript., (*2)

Here's an example of how it can be used:, (*3)

@javascript('key', 'value')

The rendered view will output:, (*4)

<script>window['key'] = 'value';</script>

So in your browser you now have access to a key variable:, (*5)

console.log(key); //outputs "value"

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website., (*6)

Support us

, (*7)

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products., (*8)

We 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. We publish all received postcards on our virtual postcard wall., (*9)

Installation

You can install the package via composer:, (*10)

``` bash composer require spatie/laravel-blade-javascript, (*11)


The package will automatically register itself. Optionally the config file can be published with ```bash php artisan vendor:publish --provider="Spatie\BladeJavaScript\BladeJavaScriptServiceProvider" --tag="config"

This is the contents of the published config file:, (*12)

return [

    /**
     * All passed values will be present in this JavaScript namespace. Set this to an empty string
     * to use the window object.
     */
    'namespace' => '',
];

If you want to customize the generated <script> tag you can publish and override the used view., (*13)

php artisan vendor:publish --provider="Spatie\BladeJavaScript\BladeJavaScriptServiceProvider" --tag="views"

After 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., (*14)

Usage

With the package installed you can make use of a @javascript Blade directive., (*15)

@javascript('key', 'value')

The rendered view will output:, (*16)

<script>key = 'value';</script>

You can also use a single argument:, (*17)

@javascript(['key' => 'value'])

This will also output:, (*18)

<script>key = 'value';</script>

When setting the namespace to eg js in the config file this will be the output:, (*19)

<script>window['js'] = window['js'] || {};js['key'] = 'value';</script>

Changelog

Please see CHANGELOG for more information what has changed recently., (*20)

Testing

bash composer test, (*21)

Contributing

Please see CONTRIBUTING for details., (*22)

Security

If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker., (*23)

Credits

This repository contains some code from the laracasts/PHP-Vars-To-Js-Transformer package written by Jeffrey Way., (*24)

License

The MIT License (MIT). Please see License File for more information., (*25)

The Versions

19/06 2018

dev-master

9999999-dev https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

07/05 2018

2.2.0

2.2.0.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

20/03 2018

2.1.2

2.1.2.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

13/02 2018

2.1.1

2.1.1.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

08/02 2018

2.1.0

2.1.0.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

28/01 2018

2.0.1

2.0.1.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

28/01 2018

dev-analysis-qrl7pV

dev-analysis-qrl7pV https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

31/08 2017

2.0.0

2.0.0.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

23/01 2017

1.1.0

1.1.0.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

27/08 2016

1.0.6

1.0.6.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

23/08 2016

dev-analysis-qJD7WQ

dev-analysis-qJD7WQ https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

01/08 2016

1.0.5

1.0.5.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

26/06 2016

1.0.4

1.0.4.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

08/06 2016

1.0.3

1.0.3.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

07/06 2016

1.0.2

1.0.2.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

07/06 2016

1.0.1

1.0.1.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

07/06 2016

1.0.0

1.0.0.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript

06/06 2016

0.0.1

0.0.1.0 https://github.com/spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel javascript blade spatie directive laravel-blade-javascript