Hi, I thought it would be fun to try to write a render method that uses erb for rending. I''m not much of a programmer, but I still like to try: module Test require ''erb'' def render(m) ERB.new(IO.read("templates/layout.html")).result(binding) do ERB.new(IO.read("templates/#{m}.html")).result(binding) end end end This doesn''t work of course, because I can''t seem to figure out how to pass a block to the layout. I can make it work just rendering index.html though. layout.html: <html> <body> <%= yield %> </body> </html> index.html: Hello <%= @name %> Anyone willing to school me on this?! :) Thanks
On 1/19/07, James Earl <jamesd.earl at gmail.com> wrote:> Hi, I thought it would be fun to try to write a render method that > uses erb for rending. I''m not much of a programmer, but I still like > to try: > > module Test > require ''erb'' > def render(m) > ERB.new(IO.read("templates/layout.html")).result(binding) do > ERB.new(IO.read("templates/#{m}.html")).result(binding) > end > end > endReplying to myself... this works, instead of using yield. Not very pretty I know :) module Test require ''erb'' def render(m) content=ERB.new(IO.read("templates/#{m}.html")).result(binding) layout=ERB.new(IO.read("templates/layout.html")).result(binding) end end
On Jan 19, 2007, at 7:02 PM, James Earl wrote:> Replying to myself... this works, instead of using yield. Not very > pretty I know :)Cool, you figured it out yourself!
On Fri, Jan 19, 2007 at 11:02:37AM -0700, James Earl wrote:> Replying to myself... this works, instead of using yield. Not very > pretty I know :) > > module Test > require ''erb'' > def render(m) > content=ERB.new(IO.read("templates/#{m}.html")).result(binding) > layout=ERB.new(IO.read("templates/layout.html")).result(binding) > end > endHey, nice tip. You want to add this to the wiki? A good place would be CampingExtras[1]. _why [1] http://code.whytheluckystiff.net/camping/wiki/CampingExtras
On 1/19/07, why the lucky stiff <why at whytheluckystiff.net> wrote:> On Fri, Jan 19, 2007 at 11:02:37AM -0700, James Earl wrote: > > Replying to myself... this works, instead of using yield. Not very > > pretty I know :) > > > > module Test > > require ''erb'' > > def render(m) > > content=ERB.new(IO.read("templates/#{m}.html")).result(binding) > > layout=ERB.new(IO.read("templates/layout.html")).result(binding) > > end > > end > > Hey, nice tip. You want to add this to the wiki? A good place > would be CampingExtras[1]. > > _whyThanks! It''s added. Feel free to improve the code if necessary :) http://code.whytheluckystiff.net/camping/wiki/CampingAndErb