Search code examples
ruby-on-railsrubymiddleman

How to render two attributes if variable is set?


I'm very new to ruby templating and am trying to figure ut a best-practice for rendering attributes.

I get my values from a yaml file, for example:

about:
    itemtype: SoftwareApplication

I then output them using the function t:

t(about.itemtype)

(about happens to be the page_class for the page)

What I want to do is output two attributes:

<div itemscope itemtype="http://schema.org/SoftwareApplication">

If the item type is set. Otherwise, I don't want to output anything.

<div>

I understand I could do an inline if-statement, but is there a cleaner way of doing this?


Solution

  • I don't know about Middleman, but you can use a helper method to decorate the output of your t(about.itemtype) with additional content in Rails.