> I have seen a number of examples where HTML code is treated as a Ruby
> block. For example, here is one taken from the Agile Rails book:
>
> <% content_for( :sidebar) do %>
>  <ul>
>      <li>this text will be rendered</li>
>      <li>and saved for later</li>
>      <li>it may contain <%= "dynamic" %> stuff</li>
> </ul>
> <% end %>
>
> I have no idea how this works.  Can someone please give me a clue as
> to how this works?  Additionally (and this is what I am really trying
> to do) I'm wondering if there isn't some way I could use this approach
> to display a block of HTML code conditionally.  Any ideas?

Not sure what you mean by conditionally... if it's something server  
side you could just do:

<% if this_expression_evaluates_to_true %>
   put your html here
<% end %>

The way content_for works is to capture the result of the block  
(everything in b/n) and save it for later.  You can get it back by doing

<%= yield :sidebar %>

-philip

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to