Skip to content

Templates & the fir tag ​

A Field Item Relationship field stores a reference: a value, an index, an ID, a key. In templates you usually want the item it points to. There are two ways to get it.

Augmentation: what the field returns on its own ​

SourceUsing the field directly gives you
AssetsThe Asset (or a list of Assets with Allow multiple). url, alt, Glide and so on all work.
Everything elseThe saved value as it is stored: the string, key, index, ID or saved object.

For lists of strings saved as value, the saved value is already what you want:

antlers
<p>Size: {{ size_select }}</p>

{{# Multiple: a list of strings #}}
{{ sizes_buttons }}<span class="pill">{{ value }}</span>{{ /sizes_buttons }}

For anything else (indexes, IDs, keys, Grid rows) use the fir tag to look up the actual item.

The fir tag ​

fir takes the handle of a FIR field, reads its saved value, finds the source field and returns the item(s) the value refers to.

Single item ​

antlers
{{ fir:shipping_method }}           {{# "express" → "Express shipping" #}}
{{ fir:mentor:name }}               {{# index 2 → the 3rd row's name #}}

Get one value from the item ​

Add a path to read a key from an object item. Use dots or colons for nested keys:

antlers
{{ fir:team_lead:name }}
{{ fir:team_lead:address.city }}
{{ fir:team_lead:address:city }}

Tag pair ​

As a pair, the tag puts the item's keys into the context:

antlers
{{ fir:editor }}
  <div class="card">
    <strong>{{ name }}</strong><br>{{ role }} · {{ email }}
  </div>
{{ /fir:editor }}

Rows come back as stored

For Grid and Replicator sources, the tag returns the row as it is stored in the content file, without augmentation. An Assets field inside a row gives you its stored path (for example people/alice.jpg), not an Asset object. Assets sources are different: those return real Asset objects, as described below.

Multiple selection ​

With Allow multiple, the pair loops over the selected items:

antlers
<div class="row">
  {{ fir:reviewers }}
    <div class="card"><strong>{{ name }}</strong></div>
  {{ /fir:reviewers }}
</div>

This also works for lists of strings, where each item is available as value:

antlers
{{ fir:sizes_checkboxes }}<span class="pill">{{ value }}</span>{{ /fir:sizes_checkboxes }}

Assets sources ​

Assets resolve to Asset objects. As a single tag you get the URL. As a pair you get the asset's fields. A path reads one field of the asset:

antlers
<img src="{{ fir:hero_image /}}" alt="">

{{ fir:hero_image }}
  <img src="{{ url }}" alt="{{ alt }}" width="{{ width }}">
{{ /fir:hero_image }}

<p>{{ fir:hero_by_index:basename }}</p>

{{ fir:featured }}<span class="pill">{{ basename }}</span>{{ /fir:featured }}

Inside loops (Grid, Replicator) ​

Inside a Replicator or Grid loop, the tag works on the fields of the current row:

antlers
{{ blocks }}
  {{ if type == "gallery_block" }}
    <figcaption>Cover: {{ fir:cover:basename }}</figcaption>
  {{ /if }}
{{ /blocks }}

FIR fields in a Global set ​

When the FIR field itself lives in a Global set, prefix it with the global set handle:

antlers
{{# 2 parts: global_set:field #}}
{{ fir:demo_settings:default_color /}}

{{# 3+ parts: global_set:field:path #}}
{{ fir:demo_settings:default_office:city }}

{{ fir:demo_settings:default_office }}
  <strong>{{ city }}</strong>, {{ country }}
{{ /fir:demo_settings:default_office }}

Global data is read for the current site, falling back to the default site.

Fields with Global sources

You don't need the prefix for a FIR field on an entry whose source is a Global. Use the field handle as usual, e.g. fir:office:country. The prefix is only for FIR fields that are stored in a Global set.

If a field in the current context has the same handle as a global set, the field wins. For example, fir:settings:x reads the field settings with the path x, not the global settings.

Parameters ​

The field and path can also be passed as parameters:

antlers
{{ fir field="team_lead" path="role" }}
{{ fir field="demo_settings:default_office" path="country" }}

path also works next to the shorthand: fir:team_lead path="email".

Syntax reference ​

SyntaxReturns
fir:fieldThe resolved item. Strings print directly. Assets print their URL.
fir:field … /fir:fieldPair: the item's keys in context. With multiple, a loop.
fir:field:pathOne value from the item (dot or colon separated). With multiple, one value per item.
fir:global:fieldSame as fir:field, for a FIR field stored in the global set global.
fir:global:field:pathSame as fir:field:path, for a FIR field in a global set.
fir field="…" path="…"Parameter form. field can be handle or global:handle.

Write these with Antlers braces, as in the examples above.

If the field doesn't exist, has no value, or its source can't be found, the tag returns nothing. It never throws, so a misconfigured field won't take a page down.

Antlers tip: closing single tags ​

Antlers pairs a tag with the next matching closing tag. If a template uses fir:hero_image as a single tag and also as a pair further down, close the single tag explicitly with /}}:

antlers
<img src="{{ fir:hero_image /}}" alt="">

{{ fir:hero_image }}
  <figcaption>{{ basename }}</figcaption>
{{ /fir:hero_image }}

Without the /}}, the first tag would swallow everything up to the closing tag.

Released under the MIT License. Made with fruit by kiwikiwi