2017-05-15 52 views
0

我正在laravel做一个项目和extends无法正常工作。在我的主页上我扩展了布局,但是当我尝试在其他页面上扩展布局时,它失败了,我在两页上都做了相同的事情。问题与Laravel延伸

这是延长工作正常

@extends('layout.app') 

@section('body') 
<center><a href="todo/create" class="btn btn-info">Add New</a></center> 
    <a href="todo/ce" class="btn btn-info">ce</a> 
<table class="table-condensed"> 
     <thead> 
     <tr> 
      <th>Title</th> 
      <th>Body</th> 
      <th>Created</th> 
      <th>Edit</th> 
      <th>Delete</th> 
     </tr> 
     </thead> 
     <tbody> 

     <tr> 
      <td>asdasd</td> 
      <td>asdasd</td> 
      <td>asdasda</td> 
      <td> <a href="">Edit</a></td> 
      <td> <a href="">Delete</a></td> 
     </tr> 

     </tbody> 
    </table> 
@endsection 

这里是哪里扩展不起作用

@extends('layout.app') 

@section('body') 
<p>Ovo je create page</p> 
@endsections 
+0

什么是错误? –

+0

打开空白page.on检查元素thers没有错误 – mihighlo

+0

您的'main_layout.blade.php'文件位于何处?它在任何子文件夹中?例如,'前/ abc/main_layout.blade.php' –

回答

0

更换@endsections@endsection我创建页面我的主页。您可以使用@yield('body')填写您的@section

例如,

main_layout.blade.php

<html> 
    <header> 
     <title>@yield('title', 'Hello')</title> 
    </header> 
    <body> 
     @yield('body') 
    </body> 
</html> 

和你的身体在文件中像my_body.blade.php

@extends('main_layout') 

@section('title', 'My page') 

@section('body') 
    <p>Hello world!</p> 
@endsection 

现在你的标题可以通过"My page"并通过parapgraph填写的 “Hello world!”。

+0

感谢您的答案仍然无法正常工作 – mihighlo

+0

你确定,你的控制器渲染正确的视图? '返回视图('pages.my_page')' –

+0

我检查所有人,一切看起来不错。我在主页上以相同的方式扩展,它works.its真混淆 – mihighlo