All Projects → spatie → Laravel Blade Javascript

spatie / Laravel Blade Javascript

Licence: mit
A Blade directive to export variables to JavaScript

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Laravel Blade Javascript

Blade
🔪 A standalone version of Laravel's Blade templating engine for use outside of Laravel.
Stars: ✭ 542 (+11.75%)
Mutual labels:  laravel, view, blade
Laravel Blade X
Use custom HTML components in your Blade views
Stars: ✭ 538 (+10.93%)
Mutual labels:  laravel, view, blade
Laravel5 Jsonapi
Laravel 5 JSON API Transformer Package
Stars: ✭ 313 (-35.46%)
Mutual labels:  api, laravel
Laravel Api Query Builder
Laravel & Lumen Api Query Builder Package
Stars: ✭ 324 (-33.2%)
Mutual labels:  api, laravel
Wpemerge
A modern, MVC-powered WordPress as a CMS workflow. 🚀
Stars: ✭ 348 (-28.25%)
Mutual labels:  view, blade
Themevel
Theme and asset management for laravel
Stars: ✭ 278 (-42.68%)
Mutual labels:  laravel, blade
Apilogger
Small laravel package for viewing api logs which can be used in debugging.
Stars: ✭ 285 (-41.24%)
Mutual labels:  api, laravel
Laravel Api
Laravel API starter Kit will provide you with the tools for making API's that everyone will love
Stars: ✭ 334 (-31.13%)
Mutual labels:  api, blade
Api Generator
PHP-code generator for Laravel framework, with complete support of JSON-API data format
Stars: ✭ 244 (-49.69%)
Mutual labels:  api, laravel
Polr
🚡 A modern, powerful, and robust URL shortener
Stars: ✭ 4,147 (+755.05%)
Mutual labels:  api, laravel
Coreui Free Laravel Admin Template
CoreUI Free Laravel Bootstrap Admin Template
Stars: ✭ 353 (-27.22%)
Mutual labels:  laravel, blade
Comments
Native comments for your Laravel application.
Stars: ✭ 390 (-19.59%)
Mutual labels:  laravel, blade
kirby-blade
Enable Laravel Blade Template Engine for Kirby 3
Stars: ✭ 20 (-95.88%)
Mutual labels:  view, blade
blade
🏃 A library for using Laravel Blade templates in WordPlate.
Stars: ✭ 28 (-94.23%)
Mutual labels:  view, blade
Laravel Api Boilerplate
Laravel API Boilerplate | Please consult the Wiki !
Stars: ✭ 300 (-38.14%)
Mutual labels:  api, laravel
Laravel Query Builder
Easily build Eloquent queries from API requests
Stars: ✭ 3,083 (+535.67%)
Mutual labels:  api, laravel
Seat
🌀✳️ SeAT: A Simple, EVE Online API Tool and Corporation Manager
Stars: ✭ 324 (-33.2%)
Mutual labels:  api, laravel
Bladeone
The standalone version Blade Template Engine without Laravel in a single php file and without dependencies
Stars: ✭ 411 (-15.26%)
Mutual labels:  laravel, view
Laravel Api Startup
"Laravel api startup" is a Laravel template project for start build an Api quickly and perfectly!
Stars: ✭ 184 (-62.06%)
Mutual labels:  api, laravel
Jikan Rest
The REST API for Jikan
Stars: ✭ 200 (-58.76%)
Mutual labels:  api, laravel

A Blade directive to export variables to JavaScript

Latest Version on Packagist Software License GitHub Workflow Status Check & fix styling Total Downloads

This package contains a Blade directive to export values to JavaScript.

Here's an example of how it can be used:

@javascript('key', 'value')

The rendered view will output:

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

So in your browser you now have access to a key variable:

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.

Support us

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.

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.

Installation

You can install the package via composer:

composer require spatie/laravel-blade-javascript

The package will automatically register itself.

Optionally the config file can be published with

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

This is the contents of the published config file:

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.

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.

Usage

With the package installed you can make use of a @javascript Blade directive.

@javascript('key', 'value')

The rendered view will output:

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

You can also use a single argument:

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

This will also output:

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

When setting the namespace to eg js in the config file this will be the output:

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

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

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

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].