From: m_seki@... Date: 2002-03-22T12:27:33+09:00 Subject: Re: erb: how to include(import,load) another erb file? > > In real applications (such as CGI), I always write the method which > > build sub part in Ruby script. > > Can one pass variables to imported files this way? How about using instance variablies? --- nav.erb <%= @a ||= 10 %> --- test.rb require 'erb/erbl' class PageWriter def initialize(template) @erb = ERbLight.new(template) end def import(path) File.open(path) do |f| ERbLight.new(f.read) end.result(binding) end def navi import('nav.erb') end def to_html @erb.result(binding) end end template = ' <%= @a=4; navi %> ' print PageWriter.new(template).to_html