1

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            
     );
2
  • 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
    Sep 24 at 9:15
  • 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
    Sep 24 at 9:36
1

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 #}

<h1>{{ status ? 'Success' : 'Failure' }}</h1>
<p>Message: {{ message }}</p>
1
  • 1
    It's working. Thanks for the quick reply.
    – Priya Goud
    Sep 24 at 10:02

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.