我计划向许多页面添加“额外内容”,假设额外内容是无限量的。
用文字来解释有点困难,所以我会尽力通过我想到的文件结构来解释它
-Views
-Products
-Prodcut.blade.php
-Extras
-extra1
- extra_pricing.blade.php
- extra_tab.blade.php
-extra2
- extra_tab.blade.php
..
-extra100
现在我希望“Extra”文件夹中的这些“extras”在产品页面中产生,每个都在适当的空间中(例如:extra_tab 将位于
- 中),这些额外文件将由用户提交,并且自动添加。
此外,它不仅会在 Product.blade.php 中完成,其他附加内容应该与其他页面匹配。
最佳答案
重新考虑您的实现。不应该有 Extras/extra{#}/extra_tab.blade.php
表示“无限”(未知?)的数字,或任何与此相关的数字。 Extras/extra1/extra_tab.blade.php
和 Extras/extra2/extra_tab.blade.php
之间的差异应由传递给 View 部分的逻辑/参数确定。
相反,一个结构将有一个 extra_tab.blade.php
文件,如下所示:
Extras/extra_tab.blade.php
其中extra_tab.blade.php
可以接收参数(例如ID),如下所示:
产品.blade.php
@foreach($extra_tabs as $key => $tab)
@include('Extras.extra_tab', array('key' => $key, 'tab' => $tab))
@endforeach
额外/extra_tab.blade.php
<?php
echo "This tab has index: ${key}. Here is the tab: \n";
print_r($tab);
?>
关于php - 将 subview Blade 部分动态添加到 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35241690/