Reference Tags
Reference tags can be used to create references to various elements in your site. They can be used in any textual fields, including Text cells within a Table field.
The syntax for reference tags looks like this:
{<Type>:<Identifier>:<Property>}
As you can see, they are made up three segments:
<Type>
– The type of element you’re creating a reference to. This can be a fully-qualified element class name (e.g.craft\elements\Entry
) or the element type’s “reference handle”.Core element types have the following reference handles:
entry
asset
tag
user
globalset
<Identifier>
– Either the element’s ID or a custom identifier supported by the element type.Entries support the following custom identifier:
sectionHandle/entry-slug
Identifiers can also include the site ID, UUID, or handle that the element should be loaded from, using an
@<Site>
syntax.<Property>
(optional) – The element property that the reference tag should return. If omitted, the element’s URL will be returned.You can refer to the element types’ class references for a list of available properties:
- craft\elements\Entry (opens new window)
- craft\elements\Asset (opens new window)
- craft\elements\Tag (opens new window)
- craft\elements\User (opens new window)
- craft\elements\GlobalSet (opens new window)
Custom field handles are also supported, for field types with values that can be represented as strings.
# Examples
The following are valid reference tags:
{asset:123:filename}
– returns the filename of an asset with the ID of123
(via craft\elements\Asset::getFilename() (opens new window)).{entry:blog/whats-on-tap}
– returns the URL of an entry in ablog
section with the slugwhats-on-tap
.{entry:blog/whats-on-tap@en:intro}
– returns the value of anintro
custom field on ablog
section entry with the slugwhats-on-tap
, loaded from the site with the handleen
.{craft\commerce\Variant:123:price}
– returns the price of a Commerce Variant object with the ID of123
.{globalset:aGlobalSet:uid}
– returns the UID of a global set with the handleaGlobalSet
.
# Parsing Reference Tags
You can parse any string for reference tags in your templates using the parseRefs filter:
{{ entry.body|parseRefs|raw }}