如何替换 Blade 中的变量?
How to replace variable in Blade?
例如我有blade模板:
$a = $parameter;
@if (count($parameter['children']) > 0)
{{$a}}
@endif
如何把if
上面的$parameter['children']
放到另一个变量中?在下面的脚本
中迭代这个变量
blade 背后的理念是从前端移除任何 php 或业务逻辑。这样做不是视图的责任。
您应该只使用控制块(if、else、ifelse、foreach 等)并输出您需要的内容。
控制器中的任何逻辑或行为都应通过将正确构造的对象传递给视图来处理。
例如你可以这样做:
@if (count($children) > 0)
@foreach($children as $child)
{{ $child->a; }}
@endforeach
@endif
例如我有blade模板:
$a = $parameter;
@if (count($parameter['children']) > 0)
{{$a}}
@endif
如何把if
上面的$parameter['children']
放到另一个变量中?在下面的脚本
blade 背后的理念是从前端移除任何 php 或业务逻辑。这样做不是视图的责任。
您应该只使用控制块(if、else、ifelse、foreach 等)并输出您需要的内容。
控制器中的任何逻辑或行为都应通过将正确构造的对象传递给视图来处理。
例如你可以这样做:
@if (count($children) > 0)
@foreach($children as $child)
{{ $child->a; }}
@endforeach
@endif