slim
slim copied to clipboard
generate html attributes only if condition is met
Hi
I have a simple use case where I must include an anchor to an element only if one is set, for example:
.my-element[id="#{ generate_anchor }"]
Where generate_anchor would look something like this:
def generate_anchor(element)
return if element[:anchor].blank?
element[:anchor]
end
This is a fairly ugly solution as it would create blank id attributes everywhere.
Is there an more elegant way to do something like this:
.my-element([id="#{ generate_anchor }"]) - if element[:anchor].present?