Conditional check in yaml file to show the proper content
yaml
Solution
YAML is a data serialisation language, so it's not meant to contain `if`/`else` style executable statements: that's the responsibility of the programming language you're using.
A simple example in Ruby to determine which config string from a YAML file to output could be defining your YAML config file as follows:
data.yml
attributes:
shipping_comment: Shipping comment / Instructions
shipping_date: Date
Then, in your program, read the file in and run the conditional there:
shipping.rb
#!/usr/bin/env ruby
require 'yaml'
config = YAML.load_file('data.yml')
attribute = true # your attribute to check here
if attribute
puts config['attributes']['shipping_comment']
else
puts config['attributes']['shipping_date']
end
Problem
How can I check `if / else` in yaml file. like: ``` if %{attribute} attributes: shipping_comment: Shipping comment / Instructions else attributes: shipping_date: Date ```