[stringtemplate-interest] Region Syntax

Gary Clark GaryC at jeld-wen.com
Tue Sep 25 17:12:10 PDT 2007


I've run into the same problem and found two solutions.  One is to use nested HashMaps as the parameter(s) and pass them around (your template syntax will look something like $param.info.name$ since StringTemplate can descend through a tree of HashMaps and arrays).  The other is to restructure your templates and call other templates in the super group.  Something like:
 
$page_begin()$
This page's content
$page_end()$
 
Both have advantages and disadvantages.  The first one can create some very complex data structures that are difficult to manage in Java and the second one is limited to a single inheritance for super groups.

-----Original Message-----
From: Andrew Hallock [mailto:andrew.hallock at gmail.com]
Sent: Tuesday, September 25, 2007 3:47 PM
To: Gary Clark
Cc: stringtemplate-interest at antlr.org
Subject: Re: [stringtemplate-interest] Region Syntax


But then my products page, which uses the same layout, needs access to different attributes - attributes that main_layout won't know about.  What happens if the formal arg checking is turned off?  Any bad side effects? 


On 9/25/07, Gary Clark < GaryC at jeld-wen.com  <mailto:GaryC at jeld-wen.com> > wrote: 

Regions inherit the parameters of the template that uses them.  Just change the line:
 
main_layout() ::= <<


to:
 
main_layout(name) ::= <<



-----Original Message-----
From: stringtemplate-interest-bounces at antlr.org [mailto: stringtemplate-interest-bounces at antlr.org]On Behalf Of Andrew Hallock
Sent: Tuesday, September 25, 2007 2:09 PM
To: stringtemplate-interest at antlr.org
Subject: Re: [stringtemplate-interest] Region Syntax


I got this to work with the following, but run into a problem with group formal args:

Layout.stg:
group layout;
main_layout() ::= <<
<html>
<head>
<title>
$@page_title()$
</title>
</head>
<body>
$@child_content()$
</body> 
</html>
>>

Then the derived group, home.stg
group home : layout;
@main_layout.page_title() ::= "Homepage" 
@main_layout.child_content() ::= "<h1>Welcome, $name$</h1>"


Setup code:
...
StringTemplate st = subgroup.GetInstanceOf("main_layout");  //subgroup holding the group "home" 

This line throws an exception because of formal arg checking : 
st.SetAttribute("name", "Andrew");

Is there a way to set attributes in the "child_content" region?  The base group file can't know all the possible attributes that might be needed for @main_layout.child_content() 

Thanks,
Andrew 


On 9/25/07, Andrew Hallock < andrew.hallock at gmail.com> wrote: 

Nevermind...I think I can get it to work with group inheritance instead of simple templates. 



On 9/25/07, Andrew Hallock <  <mailto:andrew.hallock at gmail.com> andrew.hallock at gmail.com> wrote: 

I can't seem to get the syntax right for Template Regions: 

I need to set an attribute in an outer template (specifically, setting an HTML document's title element) from within a subtemplate.

Say, for simplicity, I have a file " layout.st" which can compromise other page templates.  

layout.st would look like:
<html>
<title>
$@page_title()$
</title> 
<body>
$(content_template_name)()$
</body>
</html>

How would you use the Template Region mechanism to set the layout's title region from within the child template?  It would be the equivalent of Django's template inheritance. 

Regards,
Andrew







_______________________________________________
stringtemplate-interest mailing list
stringtemplate-interest at antlr.org  <mailto:stringtemplate-interest at antlr.org> 
http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest  <http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest> 




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20070925/e1f6c7af/attachment.html 


More information about the stringtemplate-interest mailing list