This is an example of a 3 column matrix entry that I'm trying to output as a 3-level nested list. I've been at this for days and cant figure it out. 2-levels is easy using an if - else statement but i cant get my head around 3 levels. Is there a method i should be using, Is there anything to consider with what the matrix field is outputting?
I'm sorting the list using the sort="item_1|item_2|item_3"
Example:
/apples/black/rotten
/apples/green/cortland
/apples/green/cortland
/apples/red/granny
/apples/red/granny
/bananas/green/bad
/bananas/green/bad
/bananas/yellow/good
/bananas/yellow/good
/oranges/orange/tasty
/oranges/yellow/small
/oranges/yellow/small
Any help is appreciated, even if its just a nudge in the right direction.
-a
Help get this topic noticed by sharing it on
Twitter,
Facebook, or email.
Twitter,
Facebook, or email.
-
Hi,
I’m not sure I’m following you. Can you show me a screenshot of your actual Matrix field with the data in it, as well as post an example of the HTML you’d like Matrix to generate on the front-end, based on that data?
(To have HTML show up correctly here, place it within <pre><code> and </code></pre> tags.) -
-
-
The client has requested 3 levels deep of "on-the-fly" categories for an entry. This puts ee's native categories out of reach. So this is the best I could come up as a solution. Right now I'm using the output of the matrix field to load into an flat array and then I think I'll have to use a recursive function (outside the loop) to process the data in sections. As far as ideas to convert them into a nested list the only thing I've found is a file tree like function. Any suggestions are appreciated. Hope this makes sense.
this...
Output would be like
would output...
<ul>
<li>Apples
<ul>
<li>Black
<ul>
<li>Rotten</li>
</ul>
</li>
<li>green
<ul>
<li>Cortland</li>
</ul>
</li>
</ul>
</li>
</ul>
-
-
You’d have to use a little PHP to pull that off. In your template preferences, enable PHP parsing on Output, and then you can do something like this:
<?php
$cats = array();
?>
{cats}
<?php
$cats['{level_1}']['{level_2}'][] = ['{level_3}'];
?>
{/cats}
<ul>
<?php foreach ($cats as $level1 => $level1cats): ?>
<li><?= $level1 ?>
<ul>
<?php foreach ($level1cats as $level2 => $level2cats): ?>
<li><?= $level2 L>
<ul>
<?php foreach ($level2cats as $level3): ?>
<li><?= $level3 ?></li>
<?php endforeach ?>
</ul>
</li>
<?php endforeach ?>
</ul>
</li>
<?php endforeach ?>
</ul> -
-
I can't tell you how much this is appreciated. Thank you very much.
-a -
-
Just a follow up question. What if I added an assets field to the matrix (column would be .jpgs of hypothetical fruit). Is this doable as a unordered list if i throw that wrench into the mix?
-
-
Sure. Is that happening as a 4th column, or replacing Level 3?
-
-
-
Its a 4th column so i just added another level to the array.
{assets_files}
<?php
$cats['{level_1}']['{level_2}']['{level_3}'][] = ('{filename}');
?>
{/assets_files}
i used the asset fieldtype and stuck the 3 categories into the array and it worked. But I just want to make sure that there is no issue with using the matrix fields within the assets tag pairs -
-
-
Loading Profile...



EMPLOYEE
