yamayama yamayama - 1 year ago 135
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?

Answer Source

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 }}" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download