amteich / kirby-twig

Twig templating support for Kirby CMS
MIT License
48 stars 12 forks source link

"need help" - how access form variables in twig #5

Closed dannystarkDE closed 5 years ago

dannystarkDE commented 5 years ago

hey,

i am relatively new to kirby and PHP, and have a question about the contact form. how can i access the variables $alert etc. in the template with twig?

I am currently trying to integrate a contact form on the homepage, but I lack any understanding of how to access the data within Twig.

thanks for your help.

dannystarkDE commented 5 years ago

ah sorry.. :) that's working by default...
my controller wasn't working 😄

seehat commented 5 years ago

Hey, good that you've solved it. :)

Paulexe commented 2 years ago

Hey, i have the same question, but did not find the answer on my own like @dannystarkDE :

I have a controller which returns data, that i want to access with twig:

.../controller.php: return [ 'alert' => $alert, 'data' => $data ?? false, 'success' => $success ?? false ];

How is it possible to access this data with twig?

Thanks for the plugin and help!

seehat commented 2 years ago

Hey @Paulexe, your controller must be named like the template you want to pass those variables to. This controller would only work for a template called controller.twig.

In controller.twig you would be able to access those variables for example by using the following:

{{ alert }}

See here: https://getkirby.com/docs/guide/templates/controllers