0

I'd like to use a variable inside a YAML literal block scalar.

Here's what I'd like to do:

markup: |
  <title>
    {{ title }}
  </title>

Can that be done somehow?

I appreciate that this example would be trivial to execute without using a literal block scalar, but my actual use case inside a Foundation 6 stack would contain more markup and more variables than what I'm showing here.

Anthon
  • 69,918
  • 32
  • 186
  • 246
Christopher Werby
  • 890
  • 2
  • 8
  • 15

1 Answers1

2

There is no such thing as a variable inside a literal block scalar.

First of all there are no variables in YAML (the word variable, occurs only once in the YAML specification, in an example document, nr. 2.28).
And second, this is called literal for a reason. No interpretation is done of any of the characters.

Of course it is possible that some program that loads your document does something with the text between curly braces ({}). E.g interprets it as a jinja2 template. But without knowing what such a program does or expects, it is equally valid to expect something like that for the information between angle brackets (<>).

Therefore within YAML there is no way to use variables, neither inside of literal block-style scalars, nor outside them.


As for the templating: I have worked with program that generated YAML from a template and applied templates on the loaded string scalars (by recursively walking the tree). Your example could be either.

Anthon
  • 69,918
  • 32
  • 186
  • 246
  • Thank you for your clear explanation. I'm new to Yaml and I'm only experiencing it in connection with Panini, Foundation's templating system integrated with Handlebars. I see that I merged concepts from one into capabilities that I wished to use within Yaml. Thank you for setting me straight. – Christopher Werby Aug 22 '18 at 15:52