Rendering with erb

James Earl jamesd.earl at gmail.com
Fri Jan 19 12:52:36 EST 2007


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


More information about the Camping-list mailing list