yamayama yamayama - 2 months ago 12
Twig Question

storing variable in twig?

i am starting to play with twig, but I am very noob at it.
So sorry if the question sounds utterly stupid, but well.. i looked a bit everywhere, and i didn't find anything.

So, how can i store a string input by the user into a variable in twig?

like in my template I have:

<input type="text" name="name"/>

what shall I do to store the "value" of this input into a variable?
Is here direct way to do it?

or shall i do something completely different?

if so, what should I look for?


You need to pass the variable from your controller back to your template,

    $twig->render('template.twig', [
         'name' => isset($_POST['name']) ? $_POST['name'] : '',


<input type="text" name="name" value="{{ name }}" />