How loop a list in View item view (infolist)?
Im facing a situation where a Product can have many Product variants.
So in the view-one-product view, I need to loop through all its product variants and display those variants in a list.
How can I do that?
9 Replies
You can build a new section dynamically before the “return $infolist”, by doing your foreach on the variants of your product, store this section in a variable and display it in your schema.
Something like that :
have you seen the repeatableentry?
Sorry but that doesnt really help. It just moves the question from 1 place to another.
Can you please give me an example snippet of code, showing the syntax of your
// build your variantSection with a foreach here
, involving a for loop ...
My Product
model have
My ProductVariant
have a field called name
I think @Hugo means accessing the
$infolist->getRecord()
and looping through the relationship, which is another optionYes exactly ! 👍
But I dont see any forloops in there.
So it the loop under the hood, and all I need to do is
right?
indeed, does it work?
let me try
it worked, thank you