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