[stringtemplate-interest] Region Syntax

Andrew Hallock andrew.hallock at gmail.com
Tue Sep 25 15:47:14 PDT 2007


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> 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 < 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
> 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/170618e7/attachment-0001.html 


More information about the stringtemplate-interest mailing list