References #
Fabric language supports code reuse via block references. It’s possible to reference named
document
, data
, content
, section
, and publish
blocks defined on a root level of the file.
To include a named block defined on a root level into a document, use ref
label and base
argument:
content <content-provider> "<block-name>" {
# ...
}
data <data-source> "<block-name>" {
# ...
}
section "<block-name>" {
# ...
}
document "foo" {
<block-type> ref "<block-name>" {
base = <block-identifier-with-matching-block-type>
# ...
}
content ref {
base = content.<content-provider>.<block-name>
}
}
<block-type>
isdocument
,data
,content
,section
orpublish
.<block-identifier>
is an identifier for the referenced block. It consists of a dot-separated list of all labels in a block signature:content.<content-provider>.<block-name>
orsection.<block-name>
. The block name in the identifier must not be wrapper in double quotes"
.
For the ref
blocks defined on a root level of the file, the block name is always required. If the
blocks are inside the document
block, they can be anonymous.
An anonymous
ref
block adopts a name of the referenced block. Since the final
name of the block isn’t stated explicitly, unwanted overrides can happen. A block signature must be
unique between the blocks defined on the same level of the template.Overriding arguments #
The ref
block definition can include the argument that would override the arguments provided in
the original block. This is helpful if the block’s behaviour needs adjustments per document.
For example:
content text "hello_world" {
value = "Hello, World!"
}
document "foo" {
content ref "hello_john" {
base = content.text.hello_world
value = "Hello, John!"
}
content ref {
base = content.text.hello_world
value = "Hello, New World!"
}
}