Laravel的模板
传递变量,数组 {{}}
//详情页面
public function show()
{
return view('post/show',['title'=>'this is title']);
}
<h2 class="blog-post-title">{{$title}}</h2>
@if … @endif
//详情页面
public function show()
{
return view('post/show',['title'=>'this is title','isShow' =>false]);
}
<h2 class="blog-post-title">{{$title}}</h2>
@if($isShow ==true)
<a style="margin: auto" href="/posts/62/edit">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
</a>
@endif
@foreach … @endforeach
public function index()
{
$posts = [
[
'title' =>"this is title1"
],
[
'title' =>"this is title2"
],
[
'title' =>"this is title3"
]
];
return view('post/index',['posts' => $posts]);
}
@foreach($posts as $post)
<div class="blog-post">
<h2 class="blog-post-title"><a href="/posts/62" >{{$post['title']}}</a></h2>
<p class="blog-post-meta">May 14, 2017 by <a href="/user/5">Kassandra Ankunding2</a></p>
<p>你好你...
<p class="blog-post-meta">赞 0 | 评论 0</p>
</div>
@endforeach
参数传递
上面传递的数组,还可以这样写
//列表页面
public function index()
{
$posts = [
[
'title' =>"this is title1"
],
[
'title' =>"this is title2"
],
[
'title' =>"this is title3"
]
];
$topics = [];
return view('post/index',compact('posts','topics'));
}