Thanks Andy

Andy Wardley wrote:
> 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 %]
>
I like that #waves hands bit.  It has to make the link in the 
destination directory.
I think that's a lot more work than my post processing step.  I'm not up 
to OOperl yet.
My first language was Fortran, and it shows in my thought processes.

Right now as a post process step is an
open "find tt2 -type d |"
...
split into path chunks
get the last chunk off the end of the list
if -e $path/$lastchunk.html {make symlink}


>> 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.
>
Don't  apologize.  I figured I wasn't understanding how to do it right.
Consider it one more more vote for that behaviour in tt3.
>> 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.
> [...]
> 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.
>
While we're on files, how about a lib search option relative to the 
location of the template
file.

(Or is it that way now.  If . and .. and ../.. are on the lib path, are 
those paths relative to
the location of ttree or to $template.name?)

E.g. This way Inventory.tt2 and Inventory.inc and Inventory.csv can be 
in the same directory.
Inventory.tt2 can INCLUDE Inventory.inc, which does USE DATAFILE 
("Inventory.csf") and they
will find the copy in the current directory.

and then if I have a general dependency rule that   (.*).tt2  depends on 
$1.*

>> 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") %]
>

Damn. Missed that filter.  Not indexed under debug or trouble shooting 
in the Badger book
either.  Or I missed it there.  The Badger book and I are fighting over 
the concept of macros and
wrappers.  So far the book is winning.  Admittedly with spring coming to 
sunny Alberta, the
need to get a functioning web page up kind of dominates the thinking 
right now. 




_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to