From: Chad Fowler Date: 2004-03-09T04:49:21+09:00 Subject: Re: Looking for HTML templating system On Mon, 8 Mar 2004, Andreas Schwarz wrote: # I am looking for a templating system for my forum # (http://rforum.rubyforge.org). I would prefer something lightweight like # PageTemplate over heavy XML stuff like Amrita, because the forum will # have to handle quite a lot of traffic and my server doesn't have too # much memory. But the reason why I can't use most of the templating # engines is that I want to make the forum multi-language, so that I can't # write: # # [%if logged_in%] # Logged in as [%var username%] # [%endif%] # # but would have to write something like # # [%if logged_in%] # [%var text_logged_in_as(username)%] # [%endif%] # # Does anyone know a templating system I could use? I'm not sure if anyone mentioned this previously, but the templating system included with rdoc (which is included as part of the standard ruby distribution these days) is very simple and would probably meet your needs. You would use it from your code like this (You can't do a method call in the template, so you would want to do the language-specific stuff in code and just use the template for presentation): ---begin-code-snippet--- require 'rdoc/template' # alternatively, you could load the template text from files... # just inlining it to simplify the example TEMPLATE = <<- DOC IF:logged_in %username% ENDIF:logged_in DOC values = { "username" => text_logged_in_as(username), logged_in => true } t = TemplatePage.new(TEMPLATE) res = '' t.write_html_on(res, values) browser_output_stream << res ---end-code-snippet--- rdoc/template.rb provides conditionals and loops. It's very easy to use, and with a recent ruby version, requires no additional installation. Chad