Question

In my volt template:

    <div class="container">
        {% block conteudo %}
        {% endblock %}
    </div>

I want to load dynamically that block via ajax. All of my childs have block conteudo. How i can do that?

Thanks for your help.

Was it helpful?

Solution

I think that you're mixing PHP with JavaScript.

So if you want to load something via AJAX just use empty DIV

<div class="container"></div>

then if you want to load something from server, ie part of view generated by Phalcon/Volt, create action that renders contents of that block.

In jQuery you can:

$( "#result" ).load( "some/conteudo", { maybeSome: "params" });

And you should have SomeController that have conteudoAction method that renders some/conteudo.volt view.

Your some/conteudo.volt should render only that part of view, ie:

<h3>{{ post.title }}</h3><p>{{ post.someThing }}</p>

Another way is to render you div.container contents by JavaScript with data obtained from serwer. To do that you could return JSON data from SomeController::contuendoAction and JavaScript part of your app will create HTML to your page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top