I'm looking for partial solutions with multiple In the original example, I have this idea structure: The original application .erb ( / views / layouts / application.erb ): To make my code dry, partial ( / views / shared / content.erb ): and the controller view ( / views / home / index.erb ): So the main issue here is a template block with many yielding areas and the ability to render custom HTML passes or other partial. This question is outdated, however, even when I was looking for an answer on Google it was also relevant is. I have a solution, while still not beautiful, works very well. This idea uses the rail ' controller.html. share / _partial.html.erb Hope this helps someone! yields
< Code> & lt ;! DOCTYPE html & gt; & Lt; Top & gt; & Lt; Title & gt; Some title & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div class = "page" & gt; & Lt;% = yield% & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;
& lt; Div class = "content" & gt; & Lt; Div class = "sidebar" & gt; & Lt;% = yield: sidebar% & gt; & Lt; / Div & gt; & Lt; Div class = "main" & gt; & Lt;% = yield% & gt; & Lt; / Div & gt; & Lt; / Div & gt;
& lt;% = render: partial = & Gt; 'Layout / Header'% & gt; & Lt;% = Render: Partial = & gt; 'Share / Navigation'% & gt; & Lt;% #this I% & gt; & Lt;% = Render: Layout = & gt; 'Share / Contents' & gt; & Lt;% content_for: sidebar% & gt; & Lt;% # This application will go to. ARB, not content.erb% & gt; & Lt;% = Render: Partial = & gt; 'Share / Menu'% & gt; & Lt;% end% & gt; & Lt;% = yield% & gt; & Lt;% end% & gt; & Lt;% = Render: Partial = & gt; 'Layout / Footer'% & gt;
capture method, which takes a block and stores its contents in a variable:
& lt;% = Render 'Shared / Partial', Body: Capture {%> My body content & lt;%}, footer: capture {%> My footer content & lt;%}% & gt;
& lt; Div id = "body" & gt; & Lt;% = body% & gt; & Lt; / Div & gt; & Lt; Div id = "footer" & gt; & Lt;% = Footer% & gt; & Lt; / Div & gt;
No comments:
Post a Comment