Aaarrrrrrrrgggggg!
We'll get to the cause of this in a bit.
Following the list it seems that there are TTree users and TT2
users. TT2 users are ones who call template.pm directly from
their perl programs, and write programs that write templates that
write templates that make web pages. Raw steak and the neighbors
cat for breakfast. Top of the Food Chain.
TTree users are ones who just write templates by hand, and run
ttree -a a lot.
I'm a bottom feeder TTree user. On a good day I get raisins in my
oatmeal.
I've just finished my 2nd implementation of a template
that creates a menu tree from a directory structure.
It now has a auxiliary file that specifies things to
ignore, and can override the default alphabetical order,
and the name of the link to show
This works great. To add a new advice page for growers,
I copy my content.tt2 template to
tt2/Advice/Growers/Fertilizer_Magic.tt2
edit it,
run bin/file_index
run ttree, and magically "Fertilizer Magic" appears in
all the right menus.
THANKYOU THANKYOU THANKYOU Andy.
I now have a site with 118 static pages. Doing this
by hand would not have been possible.
BUT
(You *knew* this was coming. The opening line gave it away)
I don't generally use index.html for my pages. Too many times
a goofed copy has resulted in overwriting one version with
another. Each directory has an html file with the same name
as the directory. E.g. Home has a directory Home.html. (one of
the cool features of the menu maker-- it finds these and
makes the link in the right place)
However there are people who type directory names.
Indeed, Some sites
if you land in the middle of the site, chopping components off
the end of the link is the only way to get somewhere else, and
you get the dreaded "Virtual Directory Listing FORBIDDEN"
Gaack!
I talk too much. Sorry. Get to the point, Botsford.
At present I have a separate perl script (ok, I'm not a complete
bottom feeder...) that traverses my site tree and makes symlinks
for Home/index.html -> Home.html. This is a post ttree step
before publishing the web site.
So: IS there a graceful easy way to do this inside a template?
BUT++
While working on that menu template I ran into a couple of gotchas.
Gotcha 1. If you have a block that you have concatenated
together to avoid running out of % signs. (They cost more, you
know. Semicolons are much cheaper. I get them in bigger boxes)
AND in your cleverness you make a mistake. (hang head in
shame...) the parser spits out a message like
'Unexpected token foo found in lines 87-112' Great. foo is used
7 times, WHICH foo is the problem. If ';' is the equivalent of
'%] [%' surely the parser can be beaten over the head and ears to
spit out a line number, or even spit out the line containing the
error.
(Someone is now going to tell me that there is a ttreerc option
about this...)
Gotcha 2. One of the things I don't like about template syntax
is that there is no easy way to find the logical match.
E.g. when I'm doing perl, the logic is bound by curly brackets,
and using the % key (not as expensive if they don't print) in vi
allows me to skim through to find that extra (more usually,
missing) closing bracket that made the statement that was
supposed to be executed at the end of each iteration only be
executed after the entire loop was finished.
I haven't found a way to quickly jump from [% IF &] to the
corresponding [% END %]
Of course needing to do so probably reveals that I'm not using TT
properly. I hear the Language Abuse Police (LAP) coming up the
steps.
Someone have a syntax file for VIM for tt2?
I sometimes wish that TT was inverted. E.g. instead of
everything not in a [% %] block goes to output, we had a
some form of internal {} syntax, with an explicit SAY directive.
E.g:
SAY {
This stuff goes in with a leading and trailing newline
And keeps printing until it gets to a
matching end \}
}
SAY ( This has a leading and a trailing space )
SAY ( This has a leading space and a trailing newline
)
SAY ( This has a leading space and a trailing newline
and even though the second line is indented, the spaces
of the indent don't show up because they have the same
indent as the SAY
)
SAY (No space at all)
This would break every existing template. A Bad Thing.
(I guess SAY wouldn't break it if it were just a new directive.
but a syntax change that made easy IF END matches might
be a bit tricky to do transparently.)
BUT++
In debugging my directory scanning template, I needed to
see values of variables as I was processing them. This
of course means that the output is tangled in the web page
that I was outputting.
Is there an easy way to print to standard error from
a template?
e.g. [% STDERR "$line: lname $lname chunks $chunks %]
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates