laravel - Recursing nested array in blade template -
i attempting loop out menu in laravel.
i passing nested array main blade template categories-management.blade.php
.
view::make('categories-management')->with('categories', $categories);
where $categories
is
array (size=3) 'business resources' => array (size=7) 'operations' => array (size=4) 'resource_type_id' => int 1 27 => array (size=3) 'id' => int 27 'name' => string 'design & development' (length=20) 'children' => array (size=2) ... truncated ...
i kicking of menu inside of categories-management.blade.php
this:
@include('/includes/category-menu-item', array('categories', $categories))
inside includes/category-menu-item
have following loop:
@if(is_array($categories)) <ul> @foreach($categories $key => $value) <li> @if(!is_numeric($key)) <p>{{$key}}</p> @include('/admin/includes/category-menu-item', array('categories', $value)) @else <button data-category-id="{{$value->id}}">{{$value->name}}</button> @include('/admin/includes/category-menu-item', array('categories', $value->children)) @endif </li> @endforeach </ul> @endif
this still incomplete have issues template never gets past first layer , prints out:
business resources
business resources
business resources
business resources
... etc ...
how laravel recognise new array value? or there better method this?
your @include
statements not correct. data passed view need associated array, have passed array numeric keys. have change array('categories', $value)
array('categories' => $value)
:
@if(is_array($categories)) <ul> @foreach($categories $key => $value) <li> @if(!is_numeric($key)) <p>{{$key}}</p> @include('/admin/includes/category-menu-item', array('categories' => $value)) @else <button data-category-id="{{$value->id}}">{{$value->name}}</button> @include('/admin/includes/category-menu-item', array('categories' => $value->children)) @endif </li> @endforeach </ul> @endif
Comments
Post a Comment