Robin,

Can you provide examples of code in the old template language which would help 
us understand how nested tag structures are used? Then it would be easier to 
make suggestions about how to transform it into TT code.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Robin Smidsrød
Sent: Thursday, October 19, 2006 6:44 AM
To: [email protected]
Subject: [Templates] Converting from old template language which allows nested 
tags into TT template

I'm in the process of converting an old (undocumented) template language 
into TT templates. The old template system allow tags within tags, and 
AFAIK, TT does not allow this.

After initial conversion I end up with a TT template that contains tags 
like this:

[% popup('begin','[% embed('22478997-9520-4d0f-8abc-f888e2434c81', { 
type => 'image', mimetype => 'image/gif' } ) %] What have you learned', 
{ event => 'onclick', title => '[% 
link('22478997-9520-4d0f-8abc-f888e2434c81') %]' } ) %]

PS: popup() is a function to create a popup-window (in HTML), embed() 
returns the correct <img> tag, and link() returns a pretty formatted <a>.
PS2: I know there are some bogus single-quotes in that statement aswell. 
Hopefully it will not be a problem with my proposed solution.

My first initial reaction was to try and remove the inner tags, add a 
terminating single quote and use a string concatenation character to 
include the output of the embed() function directly into the string. I 
researched the mailinglist, but found no string concatenation character 
in TT. Only some references to "." or "~" that didn't work. But I found 
a reference that suggested [% INCLUDE [% value %] %] be changed to [% 
INCLUDE $value %] which should work. This got me thinking that something 
like this should be possible:

[%
 out1 = embed('22478997-9520-4d0f-8abc-f888e2434c81', { type => 'image', 
mimetype => 'image/gif' } );
 out2 = link('22478997-9520-4d0f-8abc-f888e2434c81');
 popup('begin',"$out1 What have you learned?", { event => 'onclick', 
title => "$out2" } )
%]

Of course, since the old language supported nesting of tags there must 
some smart algorithm that reads the nesting in reverse (or something) 
and outputs numbered variables to include in the outer tag.

My regexp/LALR knowledge is a bit too weak to be able to understand 
exactly how I should write a parser that can transform the first code to 
the second. Also be alert that there can be multiple occourences of 
similar outer tags in the same text. So some sort of s//g thing is 
needed to transform them all, and of course the numbered variable 
mustn't overwrite the ones who have been defined in the earlier tags 
(document global counter). The routine doesn't need to be super-fast, as 
it will only be used once per document, and the resulting TT template 
will be stored for later display.

What I do now is just to go through the old template and exchange each 
occurence of the old template with the new TT code, and I was planning 
on using this final algorithm to fix any accidential nesting problems 
that had occured.

Am I looking at this problem all wrong? Any hints/code 
examples/suggestions are welcome.

Regards,
Robin Smidsrød


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to