Jay Taylor's notes
back to listing indexIn YAML, how do I break a string over multiple lines?
[web search]
In YAML, I have a string that's very long. I want to keep this within the 80-column (or so) view of my editor, so I'd like to break the string. What's the syntax for this? In other words, I have this:
and I'd like to have this (or something to this effect):
I'd like to use quotes as above, so I don't need to escape anything within the string. |
|||
http://symfony.com/doc/current/components/yaml/yaml_format.html |
|||||||||||||||||||||||||||||||||
|
There are Block scalar styles (
|
|
|||||
|
Perhaps add the line-folding style (>-) as well: yaml.org/spec/1.2/spec.html#id2779048
– equaeghe
Oct 7 '15 at 10:19
|
||||
|
Holy crap, thanks. YAML is nuts. 6 different formats for multi-line strings.
– Steve Bennett
Oct 7 '15 at 23:17
|
||||
|
this should be the accepted answer. MUCH more useful than only describing
> as in the current accepted answer.
– m_x
Oct 29 '15 at 14:56
|
||||
|
>- is a combination of 8.1 "Block Scalar Styles" and 8.1.1.2 "Block Chomping Indicator". In this case, > (Block Scalar Style = Literal) and - (Block Chomping Indicator = Strip). Other combinations are possible, such as |- , >+ , and |+ (+ is Keep, which keeps all trailing empty lines instead of just one). So... that brings us to 9? :-)
– Brandon Bonds
Dec 2 '15 at 16:48
|
||||
|
To preserve newlines use
is translated to "This is a very long sentence\n that spans several lines in the YAML\n but which will be rendered as a string\n with newlines preserved." |
|||||||||||||||||||||||||||||||||
|
You might not believe it, but YAML can do multi-line keys too:
|
|||||||||
|
In case you're using yml and Twig for translations in Symfony, and want to use multi-line translations in Javascript, a carriage return is added right after the translation. So even the following code:
Which has the following yml translation:
Will still result into the following code in html:
So, the minus sign in Twig does not solve this. The solution is to add this minus sign after the greater than sign in yml:
Will have the proper result, multi line translation on one line in Twig:
|
|||||||||
|
Your Answer
asked |
5 years ago |
viewed |
80907 times |
active |
Linked
Related
Technology | Life / Arts | Culture / Recreation | Science | Other | ||
---|---|---|---|---|---|---|