[Templates] A bug and a suggestion

Kelly Thompson kalexthompson at gmail.com
Thu Jan 24 06:12:22 GMT 2008


I concur.


Other than that, I lOVE TT. Really.
One more thing, you mentioned in the badger book, about creating your own
virtual methods, but you didn't show how to "use" them.

For instance, I wanted to add substr to a formating issue I had.

use Template::Stash;

$Template::Stash::LIST_OPS->{getit} = sub {
my $thing = shift;
$thing = substr($thing, 0, 1);

return $thing;
}


I want only the first two characters of a piece of a mysql timestamp.

So I split time on the "-", giving me an array of three values.
The second one being:

22 06:23:54

So I want to grab only the first two characters of that.

In a MACRO within a config template I wrote.

MACRO date(d) BLOCK;
items = d.split('-');
it = $items.2.getit();

  "$items.1/$it/$items.0";
  END;

DIDN'T WORK!!!

Then I tried replace...

it = $items.2.replace('\b+.*$', '');

Or even..

it = ${items.2}.replace('\b+.*$', '');

Ended up having to do it in perl manually.

But I was wandering......

It never showed in the Badger book, how to use a new virtual method you have
created???

(PS- I know my regexp leave much to be desired)

Please help if you can!!

Good luck on TT3, I lOVE TT2!!!



Kelly


On Jan 24, 2008 12:55 AM, Sean McAfee <eefacm at gmail.com> wrote:

> On Jan 19, 2008 3:33 AM, Andy Wardley <abw at wardley.org> wrote:
>
> > Hi Sean,
> >
> > > ok( $text =~ /"back is " . '#ffffff'/, 'col.back folded' );
> >
> > Oops!  Mea Culpa.
> >
> > > I think prototypes aren't generally a good idea, so I'd go for the
> > latter
> > > approach.
> >
> > Sounds good.
> >
> > > I'd like to
> > > propose that generated code declare only lexical variables whose names
> > > are prefixed with an underscore, that class of names being henceforth
> > > reserved for use by the TT.
> >
> > Yep, that works for me.  Or perhaps use a _tt_ prefix to be extra clear
> > that they're TT's lexical variables.
> >
>
> Thanks, Andy!  I've implemented your suggestion and checked in the fix, in
> addition to the ok() issue and the few documentation warts I mentioned.
>
> The only other issue I had noticed has to do with the HTML entity escaping
> performed by the html filter and the HTML plugin.  Both replace the
> double-quote character with the entity &quot;, but neither replaces the
> apostrophe character with &apos;.  Perhaps they should?  It seems like a
> potentially unpleasant surprise for those whose convention is to delimit
> attributes with single quotes, eg:
>
> <img src='...' alt='[% "Don't look!" | html %]'>
>
>
> --Sean
>
> _______________________________________________
> templates mailing list
> templates at template-toolkit.org
> http://mail.template-toolkit.org/mailman/listinfo/templates
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.template-toolkit.org/pipermail/templates/attachments/20080124/e93d2193/attachment.htm 


More information about the templates mailing list