<p>Your controller looks ok, though I would clean it up a bit and use more expressive variable names to reduce the surface area for bugs:</p>
<pre class="lang-php prettyprint-override"><code>$templateVariables = [
    'status' =&gt; true,
    'message' =&gt; 'Sucess'
];
return $this-&gt;renderTemplate(
    'craft-handle/test.twig',
    $templateVariables
);
</code></pre>
<p>Now you will have access to the variables <code>status</code> and <code>message</code> in your <code>test.twig</code>:</p>
<pre><code>{# templates/craft-handle/test.twig #}

&lt;h1&gt;{{ status ? 'Success' : 'Failure' }}&lt;/h1&gt;
&lt;p&gt;Message: {{ message }}&lt;/p&gt;
</code></pre>

CC BY-SA 4.0
2021-09-24T10:02:27.023Z
It's working. Thanks for the quick reply.
Priya Goud
CC BY-SA 4.0
2021-09-24T09:47:35.377Z
2021-09-24T09:47:35.377Z
MoritzLost
<p>In the plugin, I created a form and after the process, return the below response from the controller and redirect to the template. I am trying to print the response to the template but it's not working.</p>
<pre><code>$multi_res  =array(&quot;status&quot;=&gt;True, &quot;message&quot;=&gt;'Sucess');
return $this-&gt;renderTemplate(
      'craft-handle/test.twig',
      $multi_res            
     );
</code></pre>

CC BY-SA 4.0
2021-09-24T09:15:07.133Z
Can you post your twig template? The controller code looks correct, so the issue is most likely in the template. Are you getting any errors?
MoritzLost
CC BY-SA 4.0
2021-09-24T09:36:18.190Z
I want to print the response on test.twig template but I am not sure how to print it. I need help to print responses.
Priya Goud
<craft3><plugin-development><twigextension>
How to display controller response on twig template?
# How to display controller response on twig template?

(Asked by: username_0 on 2021-09-24)

In the plugin, I created a form and after the process, return the below response from the controller and redirect to the template. I am trying to print the response to the template but it's not working.
$multi_res  =array("status"=>True, "message"=>'Sucess');
return $this->renderTemplate(
      'craft-handle/test.twig',
      $multi_res            
     );

**Tags:** craft3, plugin-development, twigextension

> **Comments:**
> **username_1**: Can you post your twig template? The controller code looks correct, so the issue is most likely in the template. Are you getting any errors?  
> **username_0**: I want to print the response on test.twig template but I am not sure how to print it. I need help to print responses.  

---

## 1 answers

### Answer by username_1 on 2021-09-24. Score: 1 | Accepted answer

Your controller looks ok, though I would clean it up a bit and use more expressive variable names to reduce the surface area for bugs:
$templateVariables = [
    'status' => true,
    'message' => 'Sucess'
];
return $this->renderTemplate(
    'craft-handle/test.twig',
    $templateVariables
);

Now you will have access to the variables status and message in your test.twig:
{# templates/craft-handle/test.twig #}

{{ status ? 'Success' : 'Failure' }}
Message: {{ message }}

> **Comments:**
> **username_0**: It's working. Thanks for the quick reply.  

---

