Sherwood Botsford wrote:
> So: IS there a graceful easy way to do this inside a template?
Hi Sherwood,
You could write a small plugin that creates the symlink using the
current template.name. Something like this (untested).
package Template::Plugin::Symlinker;
use base 'Template::Plugin';
sub new {
my ($class, $context, $args) = @_;
my $file = $context->stash->get('template.name');
# ...waves hands and creates a symlink...
}
Then in each of your index pages, a simple USE would suffice:
[% USE Symlinker %]
> Gotcha 1. [...] the parser spits out a message like
> 'Unexpected token foo found in lines 87-112' Great.
Yeah sorry, that's a limitation in the parser. That's one of the
things being fixed for TT3. Off the top of my head, it's just too
hard to make it work in the TT2 parser.
> 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.
[...]
> I haven't found a way to quickly jump from [% IF &] to the
> corresponding [% END %]
I guess you would need to program a syntax file for vim so that it
knows how the if/elsif/else/end and other blocks match up. My vim-fu
is weak so I'm not even sure that's it's possible, but I bet it is.
> Someone have a syntax file for VIM for tt2?
Yes, you can get it here:
http://tt2.org/download/index.html#editors_6
Looks pretty simple though.
> I sometimes wish that TT was inverted.
I've toyed with that idea myself. It might be particularly relevant
for things like PRE_PROCESS templates where you don't want to generate
any output by default.
So instead of writing something where the entire template is a single tag:
[% site = {
...bunch of site data...
}
page = {
...bunch of page data...
}
%]
You can just forget the tag:
site = {
...bunch of site data...
}
page = {
...bunch of page data...
}
TT would "know" that you're using the inverted syntax either by a file
extension, or by the template being in a particular directory.
I also thought it might be useful for configuration files. For example,
you could replace an existing ttree configuration file that looks like this:
src = '/path/to/my/site/templates/pages'
lib = '/path/to/my/site/templates/library'
lib = '/path/to/another/template/library'
dest = '/path/to/my/site/html'
recurse = 1
With one that looked, well, more-or-less exactly the same, but with the full
power of TT to handle things like variable subsitution:
root = '/path/to/my/site'
src = "$root/templates/pages"
lib = [
"$root/templates/library",
'/path/to/another/template/library'
]
recurse = 1
And to configure variables:
variables = {
foo = "some text"
bar = { a => 'hash' }
baz = [ 'a', 'list' ]
}
Or load plugins, define filters, macros, etc.
> Is there an easy way to print to standard error from
> a template?
>
> e.g. [% STDERR "$line: lname $lname chunks $chunks %]
Yes, via the stderr filter:
[% "Hello World" | stderr %]
or
[% FILTER stderr %]
Hello [% name %]
[% END %]
A useful MACRO is:
[% MACRO debug(message) FILTER stderr;
"DEBUG >"; message; "\n";
END
%]
[% debug("Hello World") %]
HTH
A
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates