[jifty-devel] Template::Declare Updates

Alex Vandiver alexmv at bestpractical.com
Wed Sep 23 12:38:54 EDT 2009


On Wed, 2009-09-23 at 09:20 -0700, David E. Wheeler wrote:
> Ah, thanks. Can you show me a piece of code demonstrating what one  
> might want to use it for?

You can use it to manipulate the output from TD tags as they are output.
It's used internally to make the tags nest correctly, and be output to
the right place.  I can't think of many cases where you'd want or need
to frob it by hand, but it does enable things like the following:

template simple => sub {
    html {
        head {}
        body {
            Template::Declare->buffer->set_filter( sub {uc shift} );
            p { 'Whee!' }
            p { 'Hello, world wide web!' }
            Template::Declare->buffer->clear_top if rand() < 0.5;
        }
    }
};

...which outputs, with equal regularity, either:

        <html>
         <head></head>
         <body>
          <P>WHEE!</P>
          <P>HELLO, WORLD WIDE WEB!</P>
         </body>
        </html>

...or:

        <html>
         <head></head>
         <body></body>
        </html>

 - Alex



More information about the jifty-devel mailing list