Reputation: 753
In my helper method, I render a separate partial for each template:
structure=""
if(@page.theme_set = 1) #line 1
render :partial => "first_theme.html", :locals => {:structure => structure}
else
render :partial => "second_theme.html", :locals => {:structure => structure}
end
concat(structure) #line 2
Within the partials, I do this;
<% structure << header %>
<% structure << content_for_first_theme %>
<% structure << footer %>
All three are methods in the helper. But if I move line 1 and line 2 to the partial, the structure does not render. I do not want to initialize and pass a local variable to the partials but render from within the partials. Where am I going wrong?
Upvotes: 0
Views: 263
Reputation: 4499
Probably one of the most confusing questions I've read, but there are a few things here that might help get you moving:
First, your if condition will always evaluate to true, use double equals (==) to find equality.
if(@page.theme_set = 1) #this will always evaluate to true, use double equals (==) to find equality.
Next, if you're trying to render something in a view (partial), you're not going to see anything unless you use the equal sign in the erb tag <%= %>
<%= structure << footer %>
Finally, it appears that you're trying to do all of this through the same local variable and passing a reference to the partials. If this is the case, simply using an instance variable @structure should suffice and it will be available to the controller, views, and helpers so no passing is needed.
Upvotes: 0
Reputation: 3233
Please explain more.. I am not clear with this given info. I understood that you want the html string in structure to be shown on view. try <%= raw structure %>
. I am not sure that I answered your question or not!
Upvotes: 0