3

Hi I am new to Laravel 4 and have a question about loading CSS/JS files using the blade template engine. I am using an overall layout which contains a nav bar for every page. My question is if i want to include different CSS or JS files in the header of that page how would i accomplish this, i am extending the header. Here is an example

@extends('layouts.default')
@section('content')

{{HTML::script('js/example.js')}}
{{HTML::style('css/example.css')}}

@stop

Obviously my content section starts in the body of the default layout, and when i view page source on this the and tags appear in the body. Does this matter?

Any help appreciated. Thanks!

1 Answer 1

9

Roughly 3 seconds after I posted this I figured it out, I guess thats the way learning goes.

Make a header section in the view and yield that in the header like so...

View:

@extends('layouts.default')
@section('header')

{{HTML::script('js/example.js')}}
{{HTML::style('css/example.css')}}

@stop


@section('content')

// page stuff

@stop

layout:

<!DOCTYPE html>
<html>
<head>
    @yield('header')
</head>
<body>
    @yield('content')
</body>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

As a side note, if you want to extend and add another script lets say. You can use @parent. Eg: @section('scripts') @parent //extra script @stop. laravel.com/docs/templates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.