From: Frank Reiff Date: 2007-03-23T21:04:08+09:00 Subject: Re: Newbie templating question: how to combine multiple file Jano Svitok wrote: > On 3/23/07, Frank Reiff wrote: >> >> HTML editor, something along these lines: >> >> combining multiple HTML pages into a single one? >> >> Any help would be appreciated. >> >> Best regards, >> >> Frank >> > > Hi Frank, > > have a look at rails source how it is done. It's quite easy. The > following code I almost copied from there (I do template caching in a > member attribute in addition). > > I include this code in the object that > renders the templates, but with a little modifications, you can use it > from > top level scope as well (e.g. after you get rid of @'s) > > > def render(template, local_assigns = {}) > b = evaluate_locals(local_assigns) > rhtml = @templates[template] > if rhtml.nil? > template_filename = File.join(@template_dir, > template) > rhtml = ERB.new(File.read(template_filename), > nil, "%<>") > @templates[template] = rhtml > end > rhtml.result(b) > end > > def evaluate_locals(local_assigns = {}) > b = binding > local_assigns.each { |key, value| eval "#{key} = > local_assigns[\"#{key}\"]", b } > b > end Thanks. One question though. The File.join presumably simply copies the contents of the linked file, so won't this insert the enclosing tag into the output? <%=render("header.html"%>

Hello World

becomes

My Header

Hello World

-- Posted via http://www.ruby-forum.com/.