dqxhit3376 2016-07-21 14:03
浏览 39
已采纳

刀片模板在一个子视图中加载资源对其他子视图不起作用

I am facing a pretty strange problem working with templates in Laravel. I will demonstrate it with the following example.

css/custom.css

.muted{ color:red }

Layout.blade.php

<html>
  <head>
    <title> HomePage </title>
    <link href="css/custom.css" rel="stylesheet" />
  </head>
  <body>
      <p>Layout file</p>
      @yield('content') 
  </body>
</html>

subview1.blade.php

@extends('Layout')

@section('content')
   <p class="muted"> From sub view 1 </p>
@stop

subview2.blade.php

@extends('Layout')

@section('content')
     <p class="muted"> From subview 2 </p>
@stop

Actually what is happening is that for subview 2 the class muted is not applied. And console shows that it could not load the resource i.e custom/css when second view is loaded but works fine with subview1

Any pointers to the real issue and solution are highly appreciated.

EDIT

Attached is the directory structure. And I am referencing it like this.

1) dashboard_layout.blade.php (Layout File)

2) dashboard_index.blade.php ( subview1 )

3) course_index.blade.php (subview2)

dashboard_index.blade.php

@extends('teacher.dashboard.dashboard_layout')

course_index.blade.php

@extends('teacher.dashboard.dashboard_layout')

blade_stack_ques_ref

  • 写回答

1条回答 默认 最新

  • doudao1922 2016-07-21 18:34
    关注

    Actually, It's always confusing to reference the same assets using relative paths.You have to have an eagle eye to work out.Here comes Laravel's Html providers. Use them to reference your assets in your blade files as mentioned below rather than using simple link and script tags.

    Html::style('assets/css/custom.css') // For style sheets.
    Html::script('assets/js/custom.js') // For scritps.
    

    NOTE : assets directory mentioned above is under your public folder as per Laravels app structure.

    Html & Form Providers were shipped with Laravel basic app in previous versions.But in latest versions of Laravel. They are removed from the core.So above code snippet will produce an error. You can follow the minimal steps mentioned here laravelcollective to fix the issue.

    Happy Learning !

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误