From: m_seki@... Date: 2002-03-22T08:10:41+09:00 Subject: Re: erb: how to include(import,load) another erb file? Hello. > Sorry for not being able to find this by myself, > but: > how can I import another erb file from an erb file? > (like <% ERuby.import "myblock.rh" %> Sorry, erb does not support import. In filter mode, you can use as follows. (but it is not the same as ERuby.import at all.) --- body.erb: <% def import(fname) erb = File.open(fname) { |fp| ERb.new(fp.read) } erb.run end %> I'm body.erb <%= import('footer.erb')%> --- --- footer.erb: -- <%= Time.now.strftime("%Y-%m-%d") %> --- % ruby /usr/local/lib/ruby/site_ruby/1.6/erb/erb.rb body.erb I'm body.erb -- 2002-03-22 In real applications (such as CGI), I always write the method which build sub part in Ruby script. --- body2.erb: I'm body.erb <%= footer %> --- --- mycgi.rb require 'erb/erbl' ... class MyCGI def import_erb(fname) File.open(fname) { |fp| ERbLight.new(fp.read) } end .... def body erb = import_erb('body2.erb') erb.result(binding) end def footer erb = import_erb('footer.erb') erb.result(binding) end def result body rescue error_result end end