Chapter 14. Custom Templates

You can customize how ruby-web load templates:

require 'web/phprb'

Web::config['load_suffix']['rhtml'] = lambda do |scriptname|
  PHPRB::load(scriptname)
end
 
# or, if you really really love your templating language:
Web::config['load_suffix'].default = lambda do |scriptname|
  PHPRB::load(scriptname)
end

Web::load('template.rhtml') # <= will be processed by phprb

phprb is an experimental template parser derived from erb, but not as inspired by the systems invented by Sun and Microsoft. It has the following rules:

<? ... ?>
Evaluate ruby code.
<?= ... ?>
Evaluate the enclosed ruby code and print the output.
<!--- ... --->
Comment out the enclosed code.
<??, ??>
Print out literal <?? or ??>.