From: Chad Perrin Date: 2007-03-30T12:57:36+09:00 Subject: Re: simple eruby -- including files On Fri, Mar 30, 2007 at 12:29:12PM +0900, Ezra Zygmuntowicz wrote: > On Mar 29, 2007, at 4:40 PM, Chad Perrin wrote: > > >Could you provide an example? The following, an apparently direct > >translation from PHP (as far as I can tell), doesn't work. > > > >index.rhtml: > > <% > > title = "Home" > > require 'template.rhtml' > > %> > > > >template.rhtml: > > > > > > Welcome <%= title %> > > > > > >

blah blah blah

> > > > > > Erb doesn't do anything like that by default. But you can fudge it > pretty easily: > > ez work $ cat include.rb > require 'erb' > def _include(template, bind=binding) > erb = ERB.new(IO.read(File.join(File.dirname(__FILE__),template))) > erb.result(bind) > end > ez work $ cat foo.rhtml > <% require 'include' %> > <% 10.times do %> > <%= _include 'bar.rhtml' %> > <% end %> > ez socialpicks $ cat bar.rhtml > <%= "hello world!" %> Thank you. I was hoping there was something simpler (using eruby.cgi rather than erb) than rolling my own, but I do appreciate your example and will put it (or something like it) to work. I guess I just assumed too much about how eruby would work. At least now I won't waste my time trying to figure out what I'm doing wrong. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] "It's just incredible that a trillion-synapse computer could actually spend Saturday afternoon watching a football game." - Marvin Minsky