K
K
knowledge2018-05-22 10:55:28
Twig
knowledge, 2018-05-22 10:55:28

How to load data into twig template via ajax?

There is a twig template, data is passed there
render('template.html.twig', ['data' => $data])
in which the data is processed, looks something like this
{{ data.header }}
{% for item in data.items %}
{{ item }}
{% endfor %}

How can I pass json of the data type so that it gets into the template?
I can insert the title, but what about iterating over the array so as not to draw tags in ajax like
success: function (data) {
for (...)
...
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ksnk, 2018-05-22
@ksnk

Do I need to explain that the template generates html, which is given to the browser? And then ajax fires and gets the data... while the template is just a memory?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question