The Template Tag
Noel can build up output using two methods. By default, all content is
appended together in the order given on the
command line or in a
project file. This allows simple Noel command
lines that concatenate together a header, body, and footer.
java -jar $NOEL_HOME/noel.jar $line
This approach may be useful when noel is driven by scripts instead of
projects, or you are just trying out some simple Noel coding. A more
scalable approach is to gradually build up and manipulate content using
the <TEMPLATE> tag. The <TEMPLATE> tag is a regular, undefined custom
tag but is given special consideration when it is time to output a file. If
any non-whitespace has been output, the output is sent to the file and
the <TEMPLATE> tag is ignored. If content that Noel has parsed is comprised
solely of Noel tag definitions, variable manipulations, comments, and whitespace,
then the value of the <TEMPLATE> tag is sent to the output file.
foo <tag Template>bar</tag>
<tag Template>bar</tag>
| => |
foo
bar
|
The <TEMPLATE> tag allows you to construct a document
incrementally instead of sequentially. Your higher-level templates
can contain variables flags and placeholders and conditional modes which
fine-grained content can take advantage of. Below is an example of
how a page can be constructed from evolving a <TEMPLATE> tag. Several
other features such as variables,
comments and
copy content are also illustrated here.
- template.html:
-
<Tag Template title="Default Title" !description>
<html><head>
<title>$title</title>
<if description><meta name="description" content="$description"><end>
<!!-- 'head' insertion point for inserting more HEAD tags -->
<<HEAD>>
<!!-- 'CSS' insertion point for page-specific style sheets -->
<style type="text/css"><!!::
<!--
::><<CSS>><!!::
//-->
</style>::>
</head>
<body>
<<>>
</body>
</html>
</Tag>
- section_template.html:
-
<InsertTag Template@CSS>
.header { font-size: 180%; }
</InsertTag>
<InsertTag Template>
<div class='header'>Foo: The Template Tag</div>
</InsertTag>
- page.html:
-
<InsertTag Template@HEAD><Meta name="robots" content="noindex"></InsertTag>
<InsertTag Template title="Happy Page">
This is a happy page.
</InsertTag>
<html><head>
<title>Happy Page</title>
<Meta name="robots" content="noindex">
<style type="text/css">
<!--
.header { font-size: 180%; }
//-->
</style>
</head>
<body>
<div class='header'>Foo: The Template Tag</div>
This is a happy page.
</body>
</html>
|
The <TEMPLATE> tag is unlike custom tags in one very subtle
respect: <TEMPLATE> tag variables are global variables. I.e.,
these two lines are equivalent:
<tag Template title="My Title"><h1>$title</h1></tag>
<tag Template><h1>$title</h1></tag>
|
If you use global variables for everything this doesn't matter.
But as your Noel content grows you should start depending on
tag-local variables keep things simple, and this exception to the
rule emphasizes the top-level/global nature of the <TEMPLATE> tag.