批改状态:合格
老师批语:合格呢
1、练习一下blade模板的语法。如:变量渲染、foreach、if...else...
2、include、section
@extends('video.layouts.index')
@section('main')
@parent
<div style="color:red;">这是继承文件中的div</div>
@parent
<br>
<hr>
<br>
<h4>foreach练习</h4>
@foreach($data['cite'] as $cites)
<div style="color:blue;">{{$cites['alias']}}</div>
@endforeach
<h4>for练习</h4>
@for($i=0;$i<=2;$i++)
<p>{{$i}}</p>
@endfor
<?php $a=5 ?>
<h4>if...else练习</h4>
@if($a<9)
<div>{{'a小于9'}}</div>
@else
<div>{{'a大于9'}}</div>
@endif
@endsection运行结果:

小结:
在使用@include和@extend两种方法引用公共页面内容的时候,有些区别:使用@include的时候,被引用的文件成为当前文件的一部分,可以直接在当前文件中添加其他内容;使用@extends的时候
当前文件继承被引用的文件,添加其它内容的时候需要使用@session(xxx)···@endsession将添加的内容关联到模板文件的@session(xxx)@show设置的区域。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号