How do I break a string over multiple lines?

前端 未结 9 1199
有刺的猬
有刺的猬 2020-11-22 01:06

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

9条回答
  •  后悔当初
    2020-11-22 01:14

    In case you're using YAML 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:

    var javascriptVariable = "{{- 'key'|trans -}}";

    Which has the following yml translation:

    key: >
        This is a
        multi line 
        translation.
    

    Will still result into the following code in html:

    var javascriptVariable = "This is a multi line translation.
    ";
    

    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:

    key: >-
        This is a
        multi line 
        translation.
    

    Will have the proper result, multi line translation on one line in Twig:

    var javascriptVariable = "This is a multi line translation.";
    

提交回复
热议问题