D
D
Dmitry Morozov2017-01-28 22:37:20
PHP
Dmitry Morozov, 2017-01-28 22:37:20

How to get given in array in twig?

Good evening, I ran into such a problem, I run the Twig template engine:

$loader = new \Twig_Loader_Filesystem('/view/');
$twig = new \Twig_Environment($loader);
$json = $twig->render('login.twig', array('form' => $params));

As a result, when executing the render function, we pass the form parameter to the login.twig file, from the login.twig itself you expect a response in the form of json:
{
  block: form.attributes.method,
  content: "Hello"
}

Faced such a problem that when outputting, it writes an error:
An exception has been thrown during the rendering of a template ("Unexpected keyword at line 2 column 9
  block: form.attributes.m

How to make it so that in the array, the "form.attributes.method" method is read

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Morozov, 2017-01-28
@index1

Found the solution :) Stupid mistake of course...

{
  block: "{{form.attributes.method}}",
  content: "Hello"
}

D
dmitriy, 2017-01-28
@dmitriylanets

this is the first time I see that a template engine is used like this

A
Alexander Kuznetsov, 2017-01-29
@DarkRaven

Those. Are you using a template engine to output JSON?
I do not argue, a nail can be hammered with an electron microscope, but .. why?
You saw, for example, this:
php.net/manual/ru/function.json-encode.php
https://github.com/kherge-php/json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question