Loops, post fields and live data
EmVB can show your site’s content on a page: lists of entries with a Loop, the current post’s title, author and body with the post elements, and live values in ordinary elements. This guide covers the features added in 1.5. The full reference is in Theme parts.
Let visitors filter and sort a Loop
A Loop that lists a collection can offer its own filter and sort controls.
- Add a Loop (Add → Dynamic) and pick its Collection from the list of your site’s collections, or type its slug, such as
posts, under Collection slug. - Under Filter visitors can choose, pick Category or Tag.
- Turn on Visitors can change the sort order to add a Sort by list: Newest first, Oldest first or By title.
The published page shows the lists and an Apply filters button above the items. The filter offers up to 48 terms, plus All categories or All tags. The visitor’s choice goes into the page address, so it can be shared, bookmarked and cached. Each Loop keeps its own choices, and your own Only entries where filter still applies on top of the visitor’s choice. When nothing matches, the Loop says “No matching entries.”
The controls are a plain form, so they work with no script. Turn on Update filters without a page reload to swap in the new items without reloading the page. This adds a small script, only to pages that use it, and screen readers hear “Results updated.” The page reloads as usual when an item holds an element with its own script, an embed, a synced Section, another Loop or Pagination, or an extension element, and when the page has a Table of contents.
The control labels, the “No matching entries.” message and the screen reader announcement follow the page’s language: French on a French page, English for languages EmVB has no words for. A Loop that follows an archive (no Collection) has no filter controls; the archive’s own category and tag pages do that job. The HTML export shows the exported items without the controls.
Pick a Loop’s fields from lists
When a Loop has a Collection, three settings list what that collection holds. The text box under each list still takes any value.
- Only entries where: under Add a condition, choose a Filter field from the
collection’s fields and a Filter value, then Add condition (or press Enter in the value
box). A choice field offers its choices, a yes/no field offers Yes and No, and a
reference field offers the first 50 entries it can point to; other fields take a typed value.
Each condition is added to the filter as
field=value. - Excerpt field: the collection’s text fields, or Excerpt (default).
- Link pattern: the collection’s own URL pattern (as set in EmDash), or the default
/collection/{slug}. Only patterns with{slug}or{id}are offered, since those are the ones a Loop fills in.
Related posts
In a Single Post template, a Loop can list other posts like the one being read:
- Add a Loop and design its item with post elements, as for any Loop.
- Set Related posts by to Shared category or Shared tag.
- Add an Empty state inside the Loop for posts with nothing related.
The Loop lists other published posts that share at least one category or tag with the current post. The current post is never listed. Entries to show, Order and Only entries where still apply. If Only entries where names a category or tag, only those terms count as shared.
Post elements
The post elements show the current post in Single Post, Archive and Loop Item templates, and in each item of a Loop. Since 1.5 they have more settings:
| Element | Setting | What it does |
|---|---|---|
| Post title | Link to the post | Makes the title a link to the post. |
| Post author | Link to the author’s website | Links the name to the website on the author’s byline, or the entry’s author link. |
| Post author | Show the author’s bio, Show the author’s photo | Adds the bio and photo from the author’s EmDash byline, when there is one. Together they make an author box. |
| Post image | Display width (px) | Shows the image at that width, smaller on narrow screens. Leave it blank for the image’s own width. |
| Post content | Content length (blocks) | Shows only the first blocks of the body. A paragraph, heading, quote or list counts as one block. |
Live values in any field
The Dynamic data section of an element’s settings replaces a typed value with a live one: a Post field, a Site setting or a URL parameter. The typed value stays as the fallback when there is no live value.
Since 1.5 more fields can be live:
- Image: the image, alt text, caption and link.
- Image box: the image, alt text, title, text and link.
- Icon box: the title, text and link.
- Alert: the title and message.
- Testimonial: the quote, name, role and photo.
Text, Heading, Button, Link, Label, Icon, Menu item and container links could already be live.
A Post field now also works outside templates. On a published EmVB page, or on an entry of your own collection with an EmVB layout (Edit your own pages), it reads that page’s or entry’s own fields, such as its title, its address or an image field. In a Loop item, it reads that item’s entry. In the editor, the canvas shows sample values until the page has a live entry.
Live values are plain text. Links and images still go through the usual address checks, and a link from a URL parameter must stay on your site unless you turn on Allow outside sites.
Tables from a collection
A Data table can list entries of a collection. See Widgets.