Questions tagged [content-for]

51 questions
30
votes
2 answers

Ruby on Rails: provide vs content_for

I came across the view helper function "provide" today. By looking into its manual I am still confused on how it is different from "content_for". provide(name, content = nil, &block) The same as content_for but when used with streaming flushes…
Bruce
  • 1,608
  • 2
  • 17
  • 29
28
votes
3 answers

how to render partial on everything except a certain action

I have a _header.html.erb partial which is where I put my navbar on my launch page I don't want to display the navbar. this is the body of application.html.erb <%= render 'layouts/header' %>
<%= yield…
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
21
votes
2 answers

Including inline javascript using content_for in rails

I am using content_for and yeild to inject javascript files into the bottom of my layout but am wondering what the best practice is for including inline javascript. Specifically I'm wondering where the put the script type declaration: <%…
TenJack
  • 1,594
  • 4
  • 21
  • 35
12
votes
2 answers

rails partial's layouts with named yield - why is yield block never used?

I have a partial, with a layout: <%= render :partial => 'home/mobile/home', :layout => 'home/mobile/page', :locals => {:page => 'abc2'}%> The layout (page.html.erb) has yields for different blocks, such as:
<%= yield…
Peter Ehrlich
  • 6,969
  • 4
  • 49
  • 65
9
votes
5 answers

Multiple content_for on the same page

I have large block of HTML in my application that I would like to move into a shared template and then use content_for with yields to insert the necessary content. However, if I use it more than once in the same layout file the content_for just…
Jason Yost
  • 4,807
  • 7
  • 42
  • 65
8
votes
2 answers

HAML Having Multiple Lines While Using content_for, for JavaScript

I am trying to output some inline js on a page. I don't really want to add it to any JS file since it is so aribtrary and one time use. That being said, I am using haml and also trying to use content_for in order to place the JS after jquery is…
Parris
  • 17,833
  • 17
  • 90
  • 133
8
votes
2 answers

how to use content_for so that the content shows up in the layout

Am testing the content_for in my rails 3.2 app and following the rails guides but they are specific to the actual files and I cannot seem to get the yield to work: application.html.erb file: …
akkdio
  • 573
  • 2
  • 5
  • 13
7
votes
3 answers

Passing Parameters to yield in Rails 3 (or is it possible?)

I'm trying to create a dynamic content with yield and content_for. Basically i have bunch of layouts. And i dont want to create bunch of views for each layout. I want to render view parts when they are needed. For different parts of code it is ok.…
Çağdaş
  • 993
  • 1
  • 12
  • 33
6
votes
1 answer

Issue with Rails Content_for / yield - duplicated content

I'm trying to load some javascript in my application page using a named yield block, but the code is duplicated because of a generic yield that load my view pages. something like that: -----Code present in views----- <% content_for :bottom_scripts…
Guilherme
  • 61
  • 3
6
votes
1 answer

Ruby on Rails's content_for will do an automatic HTML escape?

Using Rails 3.0.6, I found that in the view, if I do a content_for :food_name, "Macaroni & Cheese" Then when I get it back using content_for(:food_name), then the & will be made into & already. It doesn't matter if I do a…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
5
votes
3 answers

Using multiple yields to insert content

I am trying to insert content on my page with yield but every time action removes whole content from the page. I have one main yield which is working fine: <%= render 'layouts/header' %>
<%= yield %> …
Cristiano
  • 3,099
  • 10
  • 45
  • 67
4
votes
2 answers

Workaround for content_for use in conjunction with fragment caching

I'm trying to insert content into the head of my page on an per element basis, so I'd like to be able to specify something like this in a partial: # _partial.html.erb <%= content_for :style %> .element { background-color: red; } <% end…
3
votes
3 answers

How could you create a "content_for" equivalent in PHP?

I've been working on a small page in PHP, one that doesn't need the power of a full-fledged framework behind it. One thing that I'm really missing from previous work in Ruby-on-Rails is the ability to effectively pass content up the page using…
Andrew
  • 42,517
  • 51
  • 181
  • 281
3
votes
1 answer

Rails 4 content_for and yield displays blank page

I'm trying to render the following partial: <% content_for :admin_content do %>

Listing All Accounts

<%= paginate (@accounts) %> ...
<%= paginate…
B. Bulpett
  • 814
  • 12
  • 27
3
votes
1 answer

Rails global content_for

Example: I have 2 partial _map.haml and _bigmap.haml. :: _map.haml - content_for :map do %script{:type => "text/javascript", :src => "http://maps.google.com/maps/api/js?sensor=true"} ... :: _bigmap.haml - content_for :bigmap do %script{:type…
xpepermint
  • 35,055
  • 30
  • 109
  • 163
1
2 3 4