Pass variable to partial?

18 views
Skip to first unread message

Ryan

unread,
Apr 9, 2013, 1:00:25 PM4/9/13
to serve...@googlegroups.com
I have no idea if this is possible or desirable, so I'd welcome comments on both. (As always, showing my level of competence! :)

I have a few different tool tips that need to be shown in various places on my page. They each show a slightly different tip, but are essentially the same. I wanted to put all of the tip html into one partial and then when I call <%= render '/path/tomy/partial/' %> pass along a variable that would be used evaluate the if/else logic inside the partial. 

So something like this is what I was thinking, but can't seem to get it work. 

On my view:
<%= render '/path/tomy/partial', options{:value => "1"}  %>

Inside the partial

<% if :value == "1" %>
  
   Show this tool tip text

<% elsif :value == "2" %>

    Show this other tool tip text

<% else :value == "3" %>

   Show this third version 

<% end %>

Of course, the simple solution is to create three partials and just call them as needed. I suppose I'm just exploring here. Thanks so much for your thoughts!

Ryan

John Long

unread,
Apr 9, 2013, 2:03:00 PM4/9/13
to serve...@googlegroups.com
At this time Serve doesn't have handling for Rails style locals. (Would love a patch for this.) Instead you can set instance variables:

    <% @value = "1" %>
    <%= render 'path/to/my/partial' %>

or, more concisely:

   <%= @value = "1"; render 'path/to/my/partial %>

--John

--
--
Serve Users Group
Mailing List: http://groups.google.com/group/serve-users/
Project: http://github.com/jlong/serve/
 
---
You received this message because you are subscribed to the Google Groups "Serve Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to serve-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jess Brown

unread,
Apr 9, 2013, 2:54:29 PM4/9/13
to serve...@googlegroups.com
Hi John,

I'm using a rails style partial with locals:

=render "/background_image", locals: {image: "/images/products/armorweave-bk.jpg"}

# background_image.html.haml
-content_for :css do 
  %style
    body.full #main { background-image: url(#{image}) }


John W. Long

unread,
Apr 9, 2013, 3:09:07 PM4/9/13
to serve...@googlegroups.com, serve...@googlegroups.com
Well there you go!

--John
Reply all
Reply to author
Forward
0 new messages