My Laravel layout is currently as follows (removed navbar etc..):
<link href="//maxcdn.bootstrapcdn.com/bootswatch/3.3.4/flatly/bootstrap.min.css"
rel="stylesheet">
<link href="{{ asset('/css/app.css') }}" rel="stylesheet">
<!-- Fonts -->
<link href='//fonts.googleapis.com/css?family=Roboto:400,300' rel='stylesheet'
type='text/css'>
<!-- Scripts -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
@yield('content')
</div>
<!-- Scripts -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="{{ asset('assets/vendor/toastr/toastr.min.js') }}"></script>
</body>
</html>
Then I attach a view to the layout:
@extends('app')
@section('content')
Content here.
@endsection
I'm confused as to, say for example, if I'm in the clinicController.php
or within a clinic route (it's a resource), then to "inject" a stylesheet and a Javascript file into the appropriate places.
Is there a way to do this? I'd imagine that @if on a certain page, display this
would work, but I'm sure there must be a more "Laravel" way to do it?
Any help would be hugely appreciated.
You may create a
section
like the following in yourview
, for example:Then also in your
layout
,@yield
that, for example:Same goes for
script
tags, for example (Alayout
may look like this withstyles
/scripts
):Update: Since Laravel 5.2, it's possible to use Stacks for
styles
/scripts
, for example:In A View:
The Template: