我的JavaScript文件中的Laravel 4 Blade语法 [英] Laravel 4 blade syntax within my javascript files

查看:49
本文介绍了我的JavaScript文件中的Laravel 4 Blade语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主页上有一些内联javascript,它们与某些刀片语法混合在一起,例如.

My home page had some inline javascript that was mixed up with some blade syntax e.g.

    <script type="text/javascript">
        @if(Auth::user())
            if(path.indexOf('/user/' + {{Auth::user()->id}} ) != -1) {
                    $( "#tabs" ).tabs();
            };
        @endif
    </script>

一直有效,直到我想将javascript移至外部file.js.每当添加刀片语法时,我都会出错.有什么办法可以在javascript files.js中融合刀片语法?我试图重命名为file.blade.js,但是没有运气...

It worked until I wanted to move the javascript to an external file.js. I got error whenever blade syntax was added. Is there a way I can fuse blade syntax in my javascript files.js? I tried renaming to file.blade.js with no luck...

推荐答案

您可以尝试将javascript文件保存在app/views文件夹中,并将其重命名为xxx.blade.php,是.blade.php,因为 Blade Engine 仅在其.blade.php并使用@include('your javascript filename')包含由Blade解析的JavaScript文件 时才对其进行解析,它将起作用.

you can try this save your javascript file in app/views folder and rename it to xxx.blade.php , yes .blade.php because Blade Engine will parse it only if its .blade.php and use @include('your javascript filename') to include the javascript file parsed by Blade, it will work.

这篇关于我的JavaScript文件中的Laravel 4 Blade语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆