[stringtemplate-interest] Region Syntax
John Snyders
jjsnyders at rcn.com
Tue Oct 2 16:29:57 PDT 2007
I found that the region mechanism was not useful to me in
creating templates for web pages. I didn't spend much time on it.
It just didn't seem the right way to go.
I also didn't use the method mentioned by Gary Clark; page_begin()
and page_end() templates don't give the desired granularity.
This way is similar to JSP includes.
What I did went something like this:
=====
group WebAppBase;
page(title, body) ::= <<
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta http-equiv="Content-Script-Type" content="text/javascript"/>
<title>$title$</title>
...
</head>
<body>
<div id="doc3" class="yui-t2">
<div id="hd">
<p>...</p>
</div>
<div id="bd">
$body$
</div>
<div id="ft">
<p>...</p>
</div>
</div>
</body>
</html>
>>
====
group SomePage : WebAppBase;
somePage(staticResourceBase, globalNav, links, messages, data, formAction)::= <<
$page(
title={My Title},
body={
<div>
<form action="$formAction$" method="post" name="f1" id="f1">
...
</form>
</div>
},...
)$
This seems to be the StringTemplate way to me. It also feels like
struts or beehive templates. The template (page) defines the holes
(title and body) and the specific page fills in those holes when
they reference the template.
-John
---- Original message ----
>Date: Tue, 25 Sep 2007 20:52:52 -0400
>From: "Andrew Hallock" <andrew.hallock at gmail.com>
>Subject: Re: [stringtemplate-interest] Region Syntax
>To: "Terence Parr" <parrt at cs.usfca.edu>
>Cc: stringtemplate-interest at antlr.org
>
> Hi Terrance,
>
> > Set @page_title in a subgroup. Joy shall be yours. :)
>
> So close, but no joy was had :)
>
> I had a subgroup overriding the layout regions as you mention - works fine - but
> I want to add attributes that are not part of the formal argument list on the
> parent group, since the subgroup overriding region has its own context and its
> own idea of what it wants to override with.
>
> group layout;
> main_layout() ::= <<
> <html>
> <head>
> <title>
> $@page_title()$
> </title>
> </head>
> <body>
> $@child_content()$
> </body>
> </html>
> >>
>
> I want to override the child_content region in a subgroup, but also supply new
> attributes based on what page the user is requesting.
>
> In code, I use StringTemplate.FormalArguments.Add() to get around this, but I
> don't know if this is correct behavior.
>
> Appreciate your feedback.
>
> Thanks,
> Andrew
>
> On 9/25/07, Terence Parr <parrt at cs.usfca.edu> wrote:
>
> On Sep 25, 2007, at 10:45 AM, Andrew Hallock 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.
>
> hi :)
>
> You cannot "set" anything from a template.
>
> > 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.
>
> Can't. that's a side-effect. Only groups can override and hence set
> a region. Just like classes and methods.
>
> Set @page_title in a subgroup. Joy shall be yours. :)
> Ter
>________________
>_______________________________________________
>stringtemplate-interest mailing list
>stringtemplate-interest at antlr.org
>http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list