magary42016-10-28 11:13:38
magary4, 2016-10-28 11:13:38

Ajax plus rendering on the server via symfony twig?

there is a simple search page

, only when I change the filter - in addition to the search results, one more block needs to be reloaded

{% extends "::" ~ ( app.request.isxmlhttprequest ? "ajax" : "layout" ) ~ ".html.twig" %}
{% block title %}{% endblock %}
{% block content %}
   ...some html
   {% block search %}
       {% for item in items %}
            <div class="row">...</div>
       {% endfor %}
   {% endblock %}

   ...some other html

    {% block someotherinfo %}
    {% endblock %}

{% endblock %}

{% block js %}{% endblock %}

in short, I want to make some kind of hybrid
on the first load, everything is drawn as usual,
when an Ajax request only block-search and block-someotherinfo get into the Ajax layout,
I think how to divide the answer into 2 parts and append it to different places on the page

$.get('url', function(data) {
     // split data to search_results and other
} );

And in general, how much is the right idea?

I don’t want to make 2 different answers for Ajax and without, I want to have one twig template

, I looked at turbolinks - it seems to be fine. if everything is correct, configure js - it will replace everything that is needed, and make twig templates - so that they don’t give away too much

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question