slim icon indicating copy to clipboard operation
slim copied to clipboard

generate html attributes only if condition is met

Open jdescelliers opened this issue 5 years ago • 0 comments

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? 

jdescelliers avatar Jun 26 '20 08:06 jdescelliers