I am trying to pass an array on template render like this:

public function actionConfirm()
   $variables['confirm'] = array(
      'name'   => 'Silvanus',
      'office' => 'OOTS',
    $this->renderTemplate('confirm', $variables);

And output it in layout like this:

{%for variable in variables%}

This is just an example, mainly after client pays using paypal I get a payment Object that I want to pass it to the confirmation layout as per explanation above. I have tried it doesn't work.

Anyone has an idea on how to achieve this?




Yes, you do it with the setRouteVariables mathod on UrlManager, like this:

    'variable' => array(
      'name' => 'silvanus',
      'office' => 'OOTS


Now you can access your variables like this in your template:

{{ variable.name }}
{{ variable.office }}

Check out the documentation on Controllers, there's an example.

The above method is how I've done it in the past, but I see now that the renderTemplate method also can be used. I think the problem is just how you access it in your templates, I think you should just do:

{{ confirm.name }}
{{ confirm.office }}
  • Thank you so much aelvan,the EDITED version of answer is what I was looking for.Cheers mate. Sep 3 '14 at 22:51
  • Can you explain the full code again please? Because I can't get it to work for me. Jun 1 '15 at 18:14

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.