Empty field in yaml
Asked Answered
C

3

128

I want to leave a value in my .yaml field empty, because in another translation there has to be something but not in this one. Just leaving it empty prints out the path of the value (...title.3).

title:
    1: String
    2: String2
    3:
Childhood answered 4/12, 2015 at 13:29 Comment(1)
Based on your comments below this seems like a Twig (or Symfony?) problem, not a YAML problem. The code you've posted is the correct way to specify a null value in YAML (as Robert points out below you can also use null or ~), so the problem is not in your YAML. You should edit your question to include all of the relevant code and add the relevant tags.Carinacarinate
C
146

You can use ~ or null.

You should read documentation of YAML and you can read Symfony Yaml Format as well

title:
    1: String
    2: String2
    3: ~
Caphaitien answered 4/12, 2015 at 13:35 Comment(4)
It still gives me the path on the website. I use the yml values in a twig file: <h4> {{ '....title.1'|trans }}<sup>7</sup> {{ '...title.2'|trans }}<sup>2</sup> {{ '...title.3'|trans }}Childhood
try with ..title[3]Caphaitien
sadly this does not work. the syntax is correct but I want to "print out" nothing in the translation where title.3 is emptyChildhood
I'm sorry but I don't understand. The question was about empty field in yaml. If you want to achive something different please edit your questionCaphaitien
O
102

If you want an empty string, rather than a null value, you can use two single quotes.

title:
    1: String
    2: String2
    3: ''
Omentum answered 13/10, 2017 at 18:23 Comment(1)
An empty string is why I came here, didn't actually need NULL - in my case I think Spring boot didn't like empty (at least with comments in line) but did like ''Winegar
R
41

According to YAML v1.2 spec:

10.3.2. Tag Resolution

Regular expression         Resolved to tag
null | Null | NULL | ~     tag:yaml.org,2002:null
/* Empty */                tag:yaml.org,2002:null

So putting null or ~ or omitting value produces the same result: tag:yaml.org,2002:null:

parent:
  key1:               # empty so "null", # is a comment!
  key2: ~             # also "null"
  key3: null          # "null" explicitly ))
  key4: !!null "null" # for the funs of "secondary tag handle: !!"
  key5: "null"        # sorry, it is a string or !!str if you like ((
Rozina answered 21/10, 2020 at 11:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.