Question

In Middleman, how can I know if a local variable exists? Local as a yaml variable. (Follow this link to know more)

For instance I can have:

row:
  first:>
    {some text}
  second:>
    {some text}

normally I would access it by data.file_name.row.first but what if I want to know if it exists?

data.file_name.row.first.nil? gives an error if does not exist...

Was it helpful?

Solution

What error does it give? If you're getting a NoMethodError, try this:

data.file_name.try(:row).try(:first).nil?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top