php - Using Laravel functions inside a javascript file that is included as an asset -


let's have piece of jquery javascript binds div on load , dynamically defines img in div. this:

$(document).ready(function() {     $("#container").html("<img href='/images/myimage.jpg/>'); }); 

if use inlined in laravel view, i'd able use html::image() , blade templates specify location of image. this:

$(document).ready(function() {     $("#container").html("{{ html::image('images/myimage.jpg', 'my image') }}"); }); 

if take piece of javascript, and, instead of inlining in view, place inside separate .js file, say, public/js/image.js, have laravel load asset;

asset::add('image.js', 'js/image.js'); 

however, since it's treated asset, neither laravel php nor blade templating code processed, literally string {{ html::image('images/myimage.jpg', 'my image') }} in resulting html, instead of templated-in values.

is there approach this?

i'm doing here. way found was:

1 - create 'js' file inside view directory tree, like

app\views\javascript\mycustomjs.blade.php 

2 - render wherever need:

<script>     @include('javascript.mycustomjs') </script> 

it's blade, processed should.

this far ideal, know, works me, now. :)


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -