Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content_for and yield #176

Closed
evansagge opened this issue Sep 1, 2011 · 5 comments
Closed

content_for and yield #176

evansagge opened this issue Sep 1, 2011 · 5 comments
Labels

Comments

@evansagge
Copy link

I have this in app/views/layouts/application.html.slim

doctype html
html
  head
    = stylesheet_link_tag "application"
    = yield :stylesheet    
    = javascript_include_tag "application"
    = yield :javascript

  body
    = render 'gitkit'
    = yield

and this in app/views/application/_gitkit.html.slim

== content_for :javascript do
  = javascript_include_tag "https://ajax.googleapis.com/ajax/libs/googleapis/0.0.4/googleapis.min.js"

div id='gitkit'

Ideally, I should see = javascript_include_tag "https://ajax.googleapis.com/ajax/libs/googleapis/0.0.4/googleapis.min.js" where = yield :javascript is in my layout, but this does not happen. The div id='gitkit' part shows up but the contents of content_for :javascript are nowhere to be found.

<!DOCTYPE html> 
<html> 
  <head> 
    <link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />
    <script src="/assets/application.js" type="text/javascript"></script>
  </head> 
  <body>
    <div id="gitkit"> </div> 
  </body>
</html>

I've tried using - content_for, = content_for, and == content_for, all to no avail.

I'm using Rails 3.1.0 with Slim 1.0.2

@minad
Copy link
Member

minad commented Sep 1, 2011

I think this is not possible if streaming is activated since the content of the layout is generated before the partials. Can you ask on a rails list please?

Please try if the issue is really streaming by turning streaming off:

Slim::Engine.set_default_options :streaming => false

@evansagge
Copy link
Author

I think I just confirmed the problem here. It looks like you can't capture view data from partials inside layouts, only templates.

@minad minad reopened this Sep 8, 2011
@minad
Copy link
Member

minad commented Sep 8, 2011

Ok, seems that partials don't allow content_for.

@minad minad closed this as completed Sep 8, 2011
@momolog
Copy link

momolog commented Jun 26, 2014

@minad Is that a rails or a slim limitation?

@momolog
Copy link

momolog commented Jun 26, 2014

I think this statement

partials don't allow content_for

is not true. content_for in partials works just fine.
It does however depend on the order in which the partials / templates are processed. More explanation here http://stackoverflow.com/questions/2026740/rails-using-content-for-after-the-corresponding-yield-inside-layout

Anyway, this is really not a SLIM issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants