[Templates] xml configuration and variables assignement ?

[prev] [thread] [next] [Date index for 2004/05/29]

From: Etienne Robillard
Subject: [Templates] xml configuration and variables assignement ?
Date: 22:04 on 29 May 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

My name is Etienne, calling from Canada.

Using the Template Toolkit, is their a way to interpolate or mix-in
variables assignment straight from an XML file?

Considering the above XML configuration file:

~ <configuration>
~    <!-- global include_path for TT2 -->
~    <include_path>/some/path/some/where</include_path>
~    <!-- templates extension -->
~    <compile_ext>.tt</compile_ext>
~    <!-- cached templates storing area -->
~    <compile_dir>/some/foo/path</compile_dir>
~    <!-- default template -->
~    <default>misc/moo.tt</default>
~    <cache_size>32</cache_size>
~    <!-- the next section is for defining templates -->
~    <template>
~        <template_name>mary</template_name>
~        <template_location>content/nowopen.tt</template_location>
~        <!-- template variables -->
~        <template_variable>Hello World!</template_variable>
~        <template_variable>Fnord!</template_variable>
~        <template_variable>The Republic Has Interpolated
Values</template_variab
le>
~    </template>
</configuration>

So right now, I used to call variables in list-context, as explained in
Randal's article from perlmonks:
http://www.perlmonks.org/index.pl?node_id=218480

Thus,
foreach my $variable
~     ( @{ $xml_in->{ template }->{ mary }->{ template_variable } })
~        {
~            print $variable,"\n";
~        }

works well for list-context, but if one would have the idea of using
hash-references (?) as if it was real variables, like in Template, could
this be done?

Consider this xml snap-shot, and tell me if my brain is jelly-like :)
<template>
	...
	<variable>AAA</variable>
	<variable>$aaa</variable>
	<variable>[% aaa %]</variable>
</template>

# single assignement might work, however
print $xml_in->{ template }->{ mary }->{ template_variable }->[2], "\n";

# but this sounds better..
print $xml_in->{ template }->{ roger }->vars()


Regards,

Etienne
-----BEGIN PGP SIGNATURE-----

iD8DBQFAuQjVfhO/J4JSDfYRAoi4AJsEoQ7/TZBn69kRgjeCofFW7NatKgCgwGDZ
ugz20fUiyBWihe4wFZsKvgs=
=cbpS
-----END PGP SIGNATURE-----

_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

[Templates] xml configuration and variables assignement ?
Etienne Robillard 22:04 on 29 May 2004

Re: [Templates] xml configuration and variables assignement ?
merlyn (Randal L. Schwartz) 01:39 on 30 May 2004

Generated at 08:56 on 15 Mar 2005 by mariachi v0.52