0

I want to pass object as a argument from phtml file how can I do this? As I've checked we can pass string using $block->setData('var','test') but didn't found for object.

  • May I know how you write block file? – Jinesh Mar 17 at 9:23
  • I've created block using $block = $this->getLayout()->createBlock('') in phtml and want to pass object as a argument on that block. – Dj3 Mar 17 at 9:38
0

a simple example to pass a variable from Magento (template, controller, etc) file to a block with php code.

Call a block using the createBlock() method:

<?php
echo $this->getLayout()->createBlock('module/template_name')
->setData('key', $obj)
->setTemplate('module/newblock.phtml')->toHtml();
| improve this answer | |
  • Using above code we can pass xsi:type="string" argument and I want to pass xsi:type="object" argument which is not possible with above solution. – Dj3 Mar 17 at 9:51
  • you can fetch object like this $block->getData('key') in your phtml – Jinesh Mar 17 at 9:55
  • I want to pass argument using set method. I don't want to get anything. – Dj3 Mar 17 at 9:57
  • but some where you used this object am I right? – Jinesh Mar 17 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.