|
Introduction to XTemplate
|
||
|
XTemplate::XMLTemplate
XTemplate::XMLTemplate is a class for a XML template. This class has
a method expand() and expand2() for expanding a given Hash data.
Here is an example.
require 'xtemplate'
# prepare an expansion data.
data = {'members' => [
{'member' => {'name' => 'name1', 'age' => 27}},
{'member' => {'name' => 'name2', 'age' => 26}},
]}
# create a template object.
tpl = XTemplate::XMLTemplate.new(<<EOS)
<html><body>
<ul>
<li id="/members/member/name" />
</ul>
</body></html>
EOS
puts(tpl.expand(data))
The result of the above is as follows:
<html><body>
<ul>
<li>name1</li><li>name2</li>
</ul>
</body></html>
Using xtemplate command
In the above section, I show you how to write a ruby script for
expanding a template using an expansion data.
XTemplate has xtemplate command, which is installed when you
installed a set of libraries.
|
||
|
This page was generated from template.xml ,intro.xml and menu.xml by xtemplate at 05/18/2003. |
||