@include如何在Laravel中的刀片模板中工作 [英] How @include works in blade templating in Laravel
问题描述
我很好奇 @include
在Laravel Blade中的工作方式,我的意思是如果我们在这样的循环中使用它
@foreach($ posts as $ post)@include('parts.post')@endforeach
我们将加载该文件 x
次,其中 x
是帖子数量,还是加载该文件一次并使用它 x
次?/p>
谢谢
刀片模板引擎通过将blade-html文件转换为php-html文件来工作. @include
仅会被替换一次,例如
<!-parts/post.blade.php->< p>这是我的帖子:{{$ post}}</p><!-some-template.blade.php->@foreach($ posts为$ post)@include('parts.post')@endforeach
将呈现为以下php-html代码并保存到视图文件中(如果要查看,请参见 storage/framework/views
):
<?php for($ posts as post){?>< p>这是我的帖子:<?php echo($ post);?></p><?php}?>
I was curious about how @include
works in Laravel Blade, I mean if we use it in a loop like this
@foreach($posts as $post)
@include('parts.post')
@endforeach
will we load this file x
times where x
is amount of posts or we load this file once and use it x
times?
Thanks
The blade template engine works by turning blade-html files into php-html files. @include
will be replaced only once e.g.
<!-- parts/post.blade.php -->
<p>This is my post: {{$post}} </p>
<!-- some-template.blade.php -->
@foreach($posts as $post)
@include('parts.post')
@endforeach
Will be rendered into the following php-html code and saved into a view file (see storage/framework/views
if you want to see this):
<?php for($posts as post){ ?>
<p>This is my post: <?php echo($post); ?> </p>
<?php } ?>
这篇关于@include如何在Laravel中的刀片模板中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!