-
What is the best approach to do that? For example, i have some kind of array inside my block, that was passed on the creation of this block in php, then i want to access that data in magewire component attached to this block - should I do this in phtml, or by any other means? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi @Kizbo, This isn't really best practice because the Magewire block should be in charge when it comes to providing data. But I can imagine at some point to want to set data onto the Magewire component. I can think of a couple of options:
$magewire->setSomeDataOntoMyProtectedProperty('hello', 'world') Just like you would do in a ViewModel. Let me know if this helps! |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for the quick reply. foreach ($item['items'] as $subItem)
echo $block->getLayout()
->getBlock("categories.item")
->setData("item", $subItem)
->toHtml(); In this case, how can i pass "$subItem" to the magewire component inside this block? |
Beta Was this translation helpful? Give feedback.
Hi, thanks for the quick reply.
I agree with you that magewire component should be the one providing data - but how can i pass this data in this scenario?:
I have some kind of a tree structure, that is rendering child blocks dynamically based on number of items inside that tree:
In this case, how can i pass "$subItem" to the magewire component inside this block?