【问题标题】:blade templating not displaying properly刀片模板未正确显示
【发布时间】:2014-07-04 07:04:55
【问题描述】:

我创建了一个刀片模板,我想根据调用它的页面添加 css 文件。 下面的文件是名为 ._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>

我尝试使用

将 css 添加到上述模板
@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')

但是@section 和 _head 的内容现在会在显示 _header 模板的内容之后显示在 body 标记内。我在这里做错了什么?提前致谢。

【问题讨论】:

  • 如果您使用刀片模板,您的文件应具有扩展名:.blade.php

标签: laravel laravel-4 blade


【解决方案1】:

你不能在你“扩展”的同一个文件中“包含”一些东西而不将它包装在一个部分中。你应该这样做:

@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

然后在您的 .heads 文件中将“header”的产量放在最底部(或任何您想要的地方)

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

或者如果文件在所有视图中保持相同 - 只需在 .heads 中执行此操作

    ....
   @include('layouts._header')
</html>

【讨论】:

  • 标题是另一个不同的文件
  • 抱歉,我必须重新阅读整篇文章才有意义。我试试看
猜你喜欢
  • 2014-09-04
  • 2019-01-15
  • 2023-04-08
  • 2020-08-21
  • 2018-03-14
  • 2014-11-07
  • 1970-01-01
  • 1970-01-01
  • 2014-11-18
相关资源
最近更新 更多