Dynamically load craft entries based on twig variable I am looking for something quite simple, but I still can't find a way to do it in twig syntax. So basically here is my code:

{% set upperlimit = 3 %}
    {% for entry in entry.getChildren() %}
        {% if loop.index0 &lt; upperlimit %}
            &lt;button type="button" class="btn btn-default ma-category-btn {% if loop.first %}first{% endif %} {% if loop.index == upperlimit %}last{% endif %}"&gt;{{ entry. title }} &lt;span class="glyphicon glyphicon-info-sign"&gt;&lt;/span&gt;&lt;/button&gt;
        {% endif %}
    {% endfor %}

&lt;button type="button"  class="btn btn-default ma-more-category-btn"&gt;VIEW MORE CATEGORIES&lt;/button&gt;


Basically when I click on the button "VIEW MORE CATEGORIES", it should load the next three children and create three more buttons like the ones in the for loop if there are enough children for that entry.

Is it possible to have this dynamic behaviour in craft and twig?
You can't use Twig for dynamic interactions on your site, as it is a server side language. Twig compiles to PHP code, which is then rendered and loaded to the DOM.

What you'd need is a script running in userland. The technique Stehen suggested is one way to do it, but you probably don't want your site's visitors to load all data right from the start, using the button simply to reveal already loaded "extra entries".

I'd say you should learn how to do AJAX loading with Javascript or jQuery. This is how you could properly address the desired behavior.

A way to make it work with your Craft template would be to split your entries list into multiple parts using the paginate tag. The first block would load right away and then with every click on that button each succeeding entry block is loaded into the DOM via Javascript.