网站策划报告,个人开发微信小程序,快手推广,南昌网站开发公司哪家公司好Blade模版简介
Blade模版的好处#xff1a; 模版继承#xff08;template inheritance#xff09;视图片段#xff08;sections#xff09;部分指令#xff1a; extend(‘xxx’)为子页面指定所继承的页面布局模版section(‘xxx’)为子页面提供所继承的页面中指定的部分…Blade模版简介
Blade模版的好处 模版继承template inheritance视图片段sections部分指令 extend(‘xxx’)为子页面指定所继承的页面布局模版section(‘xxx’)为子页面提供所继承的页面中指定的部分yield(‘xxx’)为布局模版指定部分供section使用可以声明多个创建布局模版 如我们在视图目录(/resources/views)中创建一个布局模版这里我们命名为main.blade.php这里是模版布局的代码 Document yield(‘content’) 在view目录下的about.blade.php中使用上述模版具体代码如下extends(‘main’) section(‘content’) About me {{ $name}} stop在Blade模版中调用php方法 if表达式extends(‘main’) section(‘content’) if ($first ‘John’) Hi, John else Else endif stop 除了if外还可以使用unless(相当于 if !)、foreach、forelse(foreach循环数组为空时)等。extends(‘main’) section(‘content’) About h3People I Like:/h3ulforeach ($people as $person)li{{ $person }}/liendforeach/ulstop当foreache中的数组为空是可以加个判断if来处理extends(‘main’) section(‘content’) About if (count($people)) People I Like: foreach (peopleaspeople as person) {{ $person }} endforeach endif stop