我正在使用laravel 4进行项目.有没有什么办法可以指定我想为某个视图加载的js文件.现在我把所有文件都集中在一起.
当我使用codeigniter,加载特定的js文件时,我使用库来生成脚本标记并在页脚回显它们.如下的东西
$this->data['js'] = $this->js_lib->generate('jquery');
然后在我看来
<?= $js ?>
知道如何在laravel中做到这一点?
解决方法
主要布局
main.blade.PHP
@include('includes.header') <body> <!-- main content --> <div id="main_wrapper"> <div class="page_content"> @yield('content') </div> </div> @include('includes.footer') </body>
header.blade.PHP
<head> <Meta charset="UTF-8"> <title>My Page</title> <Meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no"> <!-- common styles --> <link rel="stylesheet" href="{{ asset('assets/bootstrap.css') }}"> <!-- page specific styles --> @yield('pagespecificstyles') </head>
footer.blade.PHP
<footer> <!-- common scripts --> <script src="{{ asset('assets/js/jquery.min.js') }}"></script> <!-- page specific scripts --> @yield('pagespecificscripts')
mypage.blade.PHP
@extends('layouts.main') @section('pagespecificstyles') <!-- flot charts css--> <link rel="stylesheet" href="{{ asset('assets/lib/owl-carousel/flot.css') }}"> @stop @section('content') <div class="container"> Hello welcome to my page. </div> @endsection @section('pagespecificscripts') <!-- flot charts scripts--> <script src="{{ asset('/assets/lib/flot/jquery.flot.min.js') }}"></script> @stop