I want to detect if content was provided for content_for tag in my template, and if not fall back to default value:
<title>
<% if content_is_provided -%>
<%= yield :title -%>
<% else -%>
404 - Page Unknown
<% end -%>
</title>
Any easy way to detect this? I tried <% if :title -%>
but that didn't do much. thanks.
You can streamline the code further:
def content_exists?(name)
return instance_variable_get("@content_for_#{name}")
end
Try this:
<title>
<%= yield :title || "404 - Page Unknown" -%>
</title>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With