Frage

I have a title renderer in my application.html.slim:

title
  - if content_for?(:title)
    = yield(:title)
  - else
    | My another title

If there is a content_for :title block, than I yield it. Other way, I render default text 'my another title' in title tag.

All works great, but it seems that code above little dirty. Is there any way to refactor it?

Regards, Alex

War es hilfreich?

Lösung

I'm not certain whether the following syntax is supported by Slim, but a possible alternative would be a single line ternary output:

title = content_for?(:title) ? yield(:title) : 'My default title'
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top