2

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?

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

$this->loadLayout();

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

$this->renderLayout();

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.