Pregunta

I have a blade template that I created and I want to add css files depending on the page that it is called to. The file below is the main file called ._head.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="">

    <title>{{ 'Login' }}</title>

    <!--Core CSS -->
    {{ HTML::style('asset/bs3/css/bootstrap.min.css') }}
    {{ HTML::style('asset/css/bootstrap-reset.css') }}        
    {{ HTML::style('asset/assets/font-awesome/css/font-awesome.css') }}    
    {{ HTML::style('asset/bs3/css/bootstrap.min.css') }}

    <!-- Custom styles for this template -->

   @yield('addcss')

    <!-- Ends Here -->

    {{ HTML::style('asset/css/style.css') }}
    {{ HTML::style( 'asset/css/style-responsive.css') }}


    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]>{{ HTML::script('asset/js/ie8/ie8-responsive-file-warning.js') }}<![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
</head>

I tried to add css to the above template using

@extends('layouts._head')
    @section('addcss')
    {{ HTML::style('asset/assets/bootstrap-datepicker/css/datepicker.css') }}
    {{ HTML::style('asset/assets/bootstrap-daterangepicker/daterangepicker-bs3.css') }}
    {{ HTML::style('asset/assets/bootstrap-datetimepicker/css/datetimepicker.css')  }}
    @stop

@include('layouts._header')

But the contents of the @section and the _head are now showing up inside the body tag after the contents of _header template are displayed. What am I doing wrong here ? Thanks in advance.

¿Fue útil?

Solución

You cant "include" something on the same file you "extend" without wrapping it in a section. You should do this:

@extends('layouts._head')

@section('addcss')
{{ HTML::style('asset/assets/bootstrap-datepicker/css/datepicker.css') }}
{{ HTML::style('asset/assets/bootstrap-daterangepicker/daterangepicker-bs3.css') }}
{{ HTML::style('asset/assets/bootstrap-datetimepicker/css/datetimepicker.css')  }}
@stop

@section('header')
    @include('layouts._header')
@stop

then in your .heads file put the yield of 'header' at the very bottom (or wherever you want it)

    ....
   @yield('header')
</html>

Or if the file remains the same in all views - just do this in .heads

    ....
   @include('layouts._header')
</html>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top