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> is document, data, content, section or publish.
  • <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> or section.<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.

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!"
  }

}