3

We can pass a variable to a .phtml view file like this:

$currentTime = date("H:i", time());
$someValue = 123;

$this->loadLayout();

$this->getLayout()
    ->getBlock('newsletter_popup')
    ->assign('currentTime', $currentTime);

$this->renderLayout();

But how to pass multiple variables?

How can I pass $someValue too?


In Laravel it works like this:

return $view->with('currentTime', $currentTime)->with('someValue', $someValue);

Does it work like this in magento too?

1 Answer 1

4
$foo = array();
$foo['currentTime'] = date("H:i", time());
$foo['someValue'] = 123;

$this->loadLayout();

$this->getLayout()
    ->getBlock('newsletter_popup')
    ->assign('foo', $foo);

$this->renderLayout();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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