Closed Sananes closed 7 years ago
Dunno, what are you doing and what is failing?
Some recommendations:
$form
in a controller, as recommended by Uniform's doc.Compared to PHP templates, Twig is a more restricted environment where you can do fewer programmy things. PHP templates have access to all variables, classes and functions defined by Kirby and plugins, and to the full power of PHP. In Twig, you can do fewer things and you only have access to what is exposed explicitly (the kirby
, site
, pages
and page
objects, most Kirby helper functions, what is returned by controllers and finally anything you enable in configuration).
One possible limit when using a plugin like Uniform is that the few helper functions it uses (honeypot_field
, csrf_field
and uniform_captcha
) will not be available as Twig functions, unless you explicitly declare them:
<?php
c::set([
'twig.function.csrf_field' => 'csrf_field',
'twig.function.honeypot_field' => 'honeypot_field',
'twig.function.uniform_captcha' => 'uniform_captcha'
]);
Another option, if those functions return a HTML string, would be to just use them in your controller and return their value, which will then be available in the template:
<?php
use Uniform\Form;
return function ($site, $pages, $page) {
$form = new Form(…);
$csrf = csrf_field();
$honeypot = honeypot_field();
return compact('form', 'csrf', 'honeypot');
};
…
{{ honeypot | raw }}
…
Hi @fvsch thanks for this wonderful reply, the only issue I'm having is with the controller. It doesn't pick up the Uniform\Form part. I just get an error with Variable form
does not exist.
Again, thanks a bunch for your reply! I really appreciate it 👍
You could show a bit of your code here, but I suspect this is not a bug in kirby-twig.
Hey guys,
I'm struggling trying to get Kirby uniform to work with Twig, any recommendations as to what I could do? I'm referring to: https://github.com/mzur/kirby-uniform
Thanks in advance! :D