I have data file
short: Tom short
alt: Tom alt (this should be shown)
short: Jeff short
alt: Jeff alt (this should be shown)
short: Joel short (he doesn't have alt)
It can have either default "short" text or an alternative text. For some testimonials, I want to use alternative text for some pages, while using "short" text for others.
test.haml I am trying to write HAML statement that checks whether alternative text exists. If it does, it should be inserted; if it doesn't, standard text should be used instead.
Following example shows that
data.testimonials[person].alt properly refers to information from data, because it can be inserted manually. However, when I use the same variable in
if defined? statement, it never returns true.
Not-working 'if' way, because 'if defined?' never evaluates to true:
- ['tom','jeff','joel'].each do |person|
- if defined? data.testimonials[person].alt
Manual way (code above should return exactly this):
- ['tom','jeff'].each do |person|
- ['joel'].each do |person|
The result is this:
What am I doing wrong? Is there any way to use conditional statement that checks whether data exists?