Basic Shape#
{{ fetch "https://api.example.com/reviews" }} <article> <h2>{{ title }}</h2> <p>{{ author.name }}</p> </article>{{ /fetch }}The fetch tag is a paired tag. The opening tag contains the API URL. The closing tag ends the fetched data loop.
Inside the block, value tags read from the current JSON item:
{{ title }}reads thetitlekey.{{ author.name }}reads the nestednamekey insideauthor.
Lists And Objects#
If the selected JSON value is a list, the markup repeats once for each item.
If the selected JSON value is one object, the markup renders once.
If the response is empty, invalid, or unavailable, the block renders nothing unless you add an {{ else }} branch.
Runtime Cache#
{{ fetch }} is a runtime fetch. WordPress requests the API when the page renders, then TemplateX caches that response briefly so the same URL is not requested on every page load.
Use runtime fetches for API data that should be checked regularly.
Rules#
- The URL must start with
http://orhttps://. - The response must be valid JSON.
- The HTML inside the block is your markup.