如何在Blade模板中包括子视图? [英] How to include a sub-view in Blade templates?

查看:77
本文介绍了如何在Blade模板中包括子视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用laravel建立一个站点,但是我确实遇到了文档无法涵盖的基本问题.

I am trying to set up a site using laravel, but I'm really having trouble with basic things that the documentation just doesn't cover.

在这种情况下,我看到它说我可以使用@include('view.name')将一个视图包含在另一个视图中.什么是view.name?它保存在哪里?我尝试创建文件app/views/view.name.blade.php,但未读取.文件名如何映射到刀片名称?

In this case, I see that it says I can include one view inside another by using @include('view.name'). What is view.name? Where is it saved? I tried creating a file app/views/view.name.blade.php, but it wasn't read. How does the file name map to the blade name?

推荐答案

以下是2014年的首选解决方案.如今,您应该使用@include,如

Below was the preferred solution in 2014. Nowadays you should use @include, as mentioned in the other answer.

在Laravel视图中,点用作文件夹分隔符. 例如,我有这段代码

In Laravel views the dot is used as folder separator. So for example I have this code

return View::make('auth.details', array('id' => $id));

指向app/views/auth/details.blade.php

which points to app/views/auth/details.blade.php

要在视图中包含一个视图,您需要这样做:

And to include a view inside a view you do like this:

文件:layout.blade.php

file: layout.blade.php

<html>
  <html stuff>
  @yield('content')
</html>

文件:hello.blade.php

file: hello.blade.php

@extends('layout')

@section('content')
  <html stuff>
@stop

这篇关于如何在Blade模板中包括子视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆