Answers.Body: <p>Yes, you do it with the setRouteVariables mathod on UrlManager, like this:</p>
  
  <pre><code>craft()-&gt;urlManager-&gt;setRouteVariables(array(
      'variable' =&gt; array(
        'name' =&gt; 'silvanus',
        'office' =&gt; 'OOTS
      )
  ));
  
  $this-&gt;renderTemplate('confirm');
  </code></pre>
  
  <p>Now you can access your variables like this in your template:</p>
  
  <pre><code>{{ variable.name }}
  {{ variable.office }}
  </code></pre>
  
  <p>Check out the <a href="http://buildwithcraft.com/docs/plugins/controllers" rel="nofollow">documentation on Controllers</a>, there's an example.</p>
  
  <p>EDIT:<br>
  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:</p>
  
  <pre><code>{{ confirm.name }}
  {{ confirm.office }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-03T22:51:59.050Z
Answers.Text: Thank you so much aelvan,the EDITED version of answer is what I was looking for.Cheers mate.
Answers.UserDisplayName: Silvanus Matiku
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-06-01T18:14:56.200Z
Answers.Text: Can you explain the full code again please? Because I can't get it to work for me.
Answers.UserDisplayName: Tom De Smet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-03T07:45:32.243Z
Answers.LastActivityDate: 2014-09-03T07:54:52.340Z
Answers.LastEditDate: 2014-09-03T07:54:52.340Z
Answers.UserDisplayName: André Elvan
Body: <p>I am trying to pass an array on template render like this:</p>
  
  <pre>
  <code>
  public function actionConfirm()
  {
     $variables['confirm'] = array(
        'name'   => 'Silvanus',
        'office' => 'OOTS',
      );
      $this->renderTemplate('confirm', $variables);
  }
  </code>
  </pre>
  
  <p>And output it in layout like this:</p>
  
  <pre>
  <code>
  {%for variable in variables%}
    {{variable.name}}
    {{variable.office}}
  </code>
  </pre>
  
  <p>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.</p>
  
  <p>Anyone has an idea on how to achieve this?</p>
  
  <p>Thanks</p>
  
  <p>Cheers.</p>
  
Tags: <templating>
Title: Passing an array on Template Render
ThreadText: # Passing an array on Template Render
  
  (Asked by: username_0 on 2014-09-03)
  
  I am trying to pass an array on template render like this:
  
  ```
  
  public function actionConfirm()
  {
     $variables['confirm'] = array(
        'name'   => 'username_0',
        'office' => 'OOTS',
      );
      $this->renderTemplate('confirm', $variables);
  }
  
  ```
  
  And output it in layout like this:
  
  ```
  
  {%for variable in variables%}
    {{variable.name}}
    {{variable.office}}
  
  ```
  
  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?
  
  Thanks
  
  Cheers.
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-09-03. Score: 1 | Accepted answer
  
  Yes, you do it with the setRouteVariables mathod on UrlManager, like this:
  
  ```
  craft()->urlManager->setRouteVariables(array(
      'variable' => array(
        'name' => 'username_0',
        'office' => 'OOTS
      )
  ));
  
  $this->renderTemplate('confirm');
  
  ```
  
  Now you can access your variables like this in your template:
  
  ```
  {{ variable.name }}
  {{ variable.office }}
  
  ```
  
  Check out the [documentation on Controllers](http://buildwithcraft.com/docs/plugins/controllers), there's an example.
  
  EDIT:  
  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 }}
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you so much aelvan,the EDITED version of answer is what I was looking for.Cheers mate.  
  > **username_2**: Can you explain the full code again please? Because I can't get it to work for me.  
  
  ---
  
  