I'm trying to pass data to a block within a foreach loop.
I've created a new block search.phtml and added it to my layout.xml as follows:
<block class="Magento\CatalogSearch\Block\Advanced\Form" name="catalogsearch_advanced_form" template="Amrita_CatalogSearch::advanced/form.phtml"> <block class="Magento\CatalogSearch\Block\Advanced\Form" name="catalogsearch_advanced_search" template="Amrita_CatalogSearch::advanced/search.phtml"> <arguments> <argument name="my_arg" xsi:type="string">testvalue</argument> </arguments> </block> </block> I want to set the value of my_arg dynamically within a loop and render the search block, where i will retrieve the value of my_arg.
i've tried the following within the parent block:
$block->GetChild('search')->SetData('my_arg', $_code); $block->getChildHtml('search'); and then to retrieve:
$_code = $block->getData('my_arg') This throws an error:
Invalid method Magento\CatalogSearch\Block\Advanced\Form::GetChild(Array ( [0] => search ) ) What's the correct way to achieve this?
$block->getChild('catalogsearch_advanced_search')