Вопрос

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

Это было полезно?

Решение

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'
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top