Fetching Data

Empty Results

Use {{ else }} when a fetch block should show fallback markup for missing API data.

Add An Empty State#

php
{{ fetch "https://api.example.com/reviews" path="items" as review }}  <article>{{ review.title }}</article>{{ else }}  <p>No reviews are available right now.</p>{{ /fetch }}

The first part renders when TemplateX has one or more JSON items.

The {{ else }} part renders when the selected JSON value is empty, unavailable, invalid, or not a usable list or object.

Keep Empty States Small#

A good empty state tells the visitor what happened without exposing API details:

php
{{ fetch "https://api.example.com/events" as event }}  <article>{{ event.title }}</article>{{ else }}  <p>No events are available right now.</p>{{ /fetch }}

Avoid showing raw error messages from third-party APIs in public templates.