A loop is a {{#…}} block that repeats its markup once per entry. Inside the block, entry placeholders refer to the current entry:
{{#query:post count=3}}
<article><h3>{{title}}</h3><p>{{excerpt}}</p></article>
{{/query}}
Loop kinds
| Loop | Repeats over | Options |
|---|---|---|
{{#posts}} | The entries of the current archive, blog, or search page. Templates only. | None |
{{#query:post_type}} | Entries of one post type, anywhere. | count, paginate=1, orderby, order |
{{#taxonomy:taxonomy}} | The terms of a taxonomy. | parent, orderby, order, include |
{{#terms:taxonomy}} | The current entry’s terms in one taxonomy. | None |
{{#related}} | Entries related to the current one. | count, orderby, order |
{{#jet_query:id}} | A JetEngine Query Builder query, by id or query id. Posts and terms are entries; other rows give their fields as placeholders. | count, paginate=1, as |
{{#jet_related:relation}} | The current entry’s related items through a JetEngine relation. | of, count |
{{#jet_cct:slug}} | The items of a JetEngine Custom Content Type. | count (all for every item; 12 when omitted), order |
{{#field_name}} | The items of a field map: a gallery, a list of choices, repeater or flexible content rows. | count; size for a gallery; layout for flexible content |
{{#has:field_name}} | Not a repeat: prints its markup once, only when the field has a value. Add not=1 to print it only when the field is empty. | not |
Loop items: define the card once
A loop item is a template that holds the markup for one row or card. Reference it by name instead of repeating markup in every loop:
{{#posts:post-card}}{{/posts}}
{{#query:doc:doc-card}}{{/query}}
The same card then serves the blog, search results, and related lists. Change the card template once and every list follows.
Inside a loop
{{loop_index}}, {{loop_total}}, {{is_first}}, {{is_last}}, and {{loop_separator}} are available for numbering, first and last styling, and separators.
Loops in the header and footer
Header and footer templates can hold loops too: the latest posts in a footer column, the doc categories in a header menu, a site-wide field such as opening hours.
<ul class="footer__latest">
{{#query:post count=3}}<li><a href="{{permalink}}">{{title}}</a></li>{{/query}}
</ul>
Outside a loop, a header or footer shows only site placeholders and site-wide field maps. {{title}} on its own stays as text there, because the header does not belong to one entry.
With Soft Navigation on, only the page content changes when a visitor clicks a link. A header or footer loop that depends on the current page keeps what the first page showed.
Pagination
Add paginate=1 to a {{#query}} loop (archive loops paginate with the main query). Then place {{pagination}} after the loop for Delta’s default controls, or compose your own from {{pagination_current}}, {{pagination_total}}, {{pagination_prev_url}}, and {{pagination_next_url}}.
One rule to remember
{{#posts}} works only in templates, where a main query exists. In a single page’s own Delta HTML, use {{#query:post_type}} instead. The agent knows this rule; if you see literal {{#posts}} text on a page, see Page is broken.