好的,我有一个看起来像这样的导航对象:
Array
(
[3] => stdClass Object
(
[nav_title] => page title 1
[parent_id] =>
[page_url] => /page-title-1
[top_nav_flag] => 1
[children] => Array
(
[4] => stdClass Object
(
[nav_title] => page title 2
[parent_id] => 3
[page_url] => /page-title-1/page-title-2
[top_nav_flag] => 1
[children] => Array
(
)
)
[5] => stdClass Object
(
[nav_title] => page title 3
[parent_id] => 3
[page_url] => /page-title-1/page-title-3
[top_nav_flag] => 1
[children] => Array
(
)
)
[6] => stdClass Object
(
[nav_title] => page title 4
[parent_id] => 3
[page_url] => /page-title-1/page-title-4
[top_nav_flag] => 1
[children] => Array
(
)
)
)
)
[7] => stdClass Object
(
[nav_title] => page title 5
[parent_id] =>
[page_url] => /page-title-5
[top_nav_flag] => 1
[children] => Array
(
[8] => stdClass Object
(
[nav_title] => page title 6
[parent_id] => 7
[page_url] => /page-title-5/page-title-6
[top_nav_flag] => 1
[children] => Array
(
[11] => stdClass Object
(
[nav_title] => page title 7
[parent_id] => 8
[page_url] => /page-title-5/page-title-6/page-title-7
[top_nav_flag] => 1
[children] => Array
(
)
)
)
)
[9] => stdClass Object
(
[nav_title] => page title 8
[parent_id] => 7
[page_url] => /page-title-5/page-title-8/
[top_nav_flag] => 1
[children] => Array
(
)
)
[10] => stdClass Object
(
[nav_title] => page title 9
[parent_id] => 7
[page_url] => /page-title-5/page-title-9/
[top_nav_flag] => 1
[children] => Array
(
)
)
)
)
等等。
现在我要做的就是让它能够动态使用特定的"模板"对于每个导航。所以通常情况下我会通过导航器@foreach,它在这种情况下真的无法工作,因为我有子导航,而且我正在寻找一种比@foreach更好的方式然后@if(!empty) (孩子))有点交易,我需要一种动态传递导航模板的方法来渲染每个导航和子导航而不管深度。在某些情况下,导航很简单,每个行项都是这样的:
<li>
<a href="/url">url text</a>
@if($subNav) <ul> {{ $subNav }} </ul> @endif
</li>
并且上面的$ subNav需要提供它自己的结构,虽然在我的情况下,结构是从每个导航行项目的父导航到子导航的相同结构,区别仅在于子导航是每个嵌套在父
但有时候它更复杂,如:
<li>
<div class="row">
<div class="large-1 columns">
<i class="list"></i>
</div>
<div class="large-11 columns">
<input type="text" name="nav[$nav_id]" value="$nav_title">
</div>
</div>
<ol>
{{ sub nav goes here }}
</ol>
</li>
这里的另一个问题是,在某些情况下会有一个页眉/页脚特定项目,所以我需要为此添加条件,或者只是使用一组不同的数据重新渲染导航(即过滤器)分页控制器中的分色。
我想我的问题是,我将如何创建这样的模板扩展程序或者您要完成此任务?