Have a Laravel 4 web site that uses a layout where jquery, boostrap, etc are loaded at the bottom of the page:
<html>
<body>
<!-- stuff -->
<script src=...jquery, bootstrap, etc...></script>
</body>
</html>
In some of the pages on the site I'm also using a partial view, and the view uses a script that depends on the bottom-of-the-page scripts. To keep things clean I'd like for the script to be part of the view file itself so that whenever the view is included its corresponding javascript is included as well. However, when the script is part of the view, it fails because the script tags will come before the dependencies at the bottom of the page.
Is there any nice way using something like blade's @yield
and @section
directives to keep the script in the same file as the view, but have it load in a section of the layout below the javascript dependencies? I don't believe I can use @yield
/@section
because the partial does not @extend
any layout. It is simply @included
in the views that need it.
So what I'd like in the end is something like:
partial.blade.php:
<div><!-- partial's html stuff --></div>
<script><!-- partial's script stuff --></div>
view.blade.php:
@extends('layout')
@section('content')
@include('partial')
@stop
layout.blade.php
<html>
<body>
@yield('content')
<script><!-- jquery, bootstrap, etc. --></script>
</body>
</html>
final html output:
<html>
<body>
<div><!-- partial's html stuff --></div>
<script src=...jquery, bootstrap, etc...></script>
<script><!-- partial's script stuff --></div>
</body>
</html>
Obviously, the easy answer is to load the dependencies in the <head>
tag, but I'd like to know if it's possible to avoid this.