Silverstripe Version: 4.1
No surprises… I’m new to SS and it’s template lang.
I have a nested multi dim arrays that I need to modify and output. I have tried using an ArrayList of ArrayData’s but found I couldn’t modify a value nor output the values. I got further with the output than I did using native arrays. I at least got the first label out but couldn’t iterate the values key.
In normal PHP it’s:
# Static atm, eventually pulled from somewhere
$all_filters = [
[
'label' => "SOME FILTER",
'filter' => 'category',
'values' => [
'Durapipe' =>
[
'checked' => ''
],
'Nupi' =>
[
'checked' => ''
],
'UPP' =>
[
'checked' => ''
],
'Sumps' =>
[
'checked' => ''
],
'Valves and Fittings' =>
[
'checked' => ''
]
]
],
[
'label' => 'ANOTHER FILTER',
'filter' => 'sub_category',
'values' => [
'Smartflex' =>
[
'checked' => '',
],
'Smart Conduit' =>
[
'checked' => '',
]
]
],
];
# If the filter is active, set it as so for render
foreach ($all_filters as $key => $filters)
{
if ($value = $request->getVar($filters['filter']))
{
$values = explode(',', $value);
foreach ($values as $value)
{
$all_filters[$key]['values'][$value]['checked'] = 'checked';
}
}
}
(excuse the formatting… this forum really gives me the sh!ts!)
So that structure works as I’d hoped… but I can’t seem to output it. This get’s me basically nothing. Just one checkbox with a title of 1.
<% loop $all_filters %>
<div class="filter-title">$label</div>
<% loop $values %>
<div class="filter-container">
<input id="todo" type="checkbox" name="$label" class="filter" value="$label" $checked/>
<label for="todo">$label</label>
</div>
<% end_loop %>
<% end_loop %>
Appreciate any help