Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yield content or yield

I'm doing the following in my application template:

<%= yield(:content) or yield %>

I have a questions template that is nested within the application template. However, for my questions index, I want just want to display the application template, not the questions template.

As such, I override it like this:

  format.html { render :layout => "application"} 

This overrides the template fine such that the application template is rendered, not the question template. However, it doesn't seem like the "or yield" statement is working; my content is blank. It works fine when I change the application template to this:

<%= yield %>

I need the original statement though so I can have the nested template. I'd prefer not to have to write content_for's across the entire site in order to have a nested template.

Any thoughts?

like image 464
ckarbass Avatar asked Feb 06 '26 18:02

ckarbass


1 Answers

Something like this should do the trick:

In place of

 <%= yield(:content) or yield %>

use:

<%= content_for?(:content) ? yield(:content) : yield %>

Hope this helps.

like image 117
Concordia Discors Avatar answered Feb 08 '26 15:02

Concordia Discors



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!