Warren Smith | 3 Jul 23:06

Dynamic Templates with Petal

I'm having troubles getting dynamic includes to work. I'm trying to do
something like this:

--- site.html
<html>
  ... header stuff ...
    <div metal:use-macro="${content_template}#content"></div>
  ... footer stuff ...
</html>

where content_template is a value passed to the Petal object on
process() and contains a valid path to a file which contains

<div metal:define-macro="content">
  stuff stuff stuff
</div>

Petal seems to ignore ${content_template} in this case and not parse it.
Instead, it looks for a file name ${content_template}. Is there a way
around this?

Jean-Michel Hiver | 4 Jul 01:19

Re: Dynamic Templates with Petal

Warren Smith wrote:
> I'm having troubles getting dynamic includes to work. I'm trying to do
> something like this:
> 
> --- site.html
> <html>
>   ... header stuff ...
>     <div metal:use-macro="${content_template}#content"></div>
>   ... footer stuff ...
> </html>

Err... ouch - that's not going to work. TAL processing happens once the 
template has been compiled as a subroutine. METAL stuff is done at 
compile-time, and at that stage there is no context to take the value from.

I think the way you could do this would be defining a 'dyna_include' 
modifier, i.e. something like:

package Petal::Hash::Dyna_Include;
use base Petal::Hash::String;
use warnings;
use strict;

sub process
{
     my $self = shift;
     my $hash = shift;
     my $args = shift;

     # turns ${content_template}#content into what it should be
(Continue reading)

Warren Smith | 19 Jul 22:06

Dereferencing SCALAR references correctly

if you do this:

template.html
-------------
<div petal:content="vals/var1"></div>

program.pl
----------
$var1 = "Hello";
$var2 = "Hello2";

%vals = ( var1=>\$var1, var2=>\$var2);
$tpl = new Petal(...);
echo $tpl->process({vars => \@vals});

Hello and Hello2 are not set. you see SCALAR references.

Changing the last part of Petal/Hash/Var.pm to

Warren Smith | 19 Jul 22:07

cont'd: Dereferencing SCALAR references correctly

grr. silly email client......

if you do this:

template.html
-------------
<div petal:content="vals/var1"></div>

program.pl
----------
$var1 = "Hello";
$var2 = "Hello2";

%vals = ( var1=>\$var1, var2=>\$var2);
$tpl = new Petal(...);
echo $tpl->process({vars => \@vals});

Hello and Hello2 are not set. you see SCALAR references.

Changing the last part of Petal/Hash/Var.pm to

    # return '' unless (defined $current);
    # $current = "$current" if (defined $current);
    return $$current if isa($current, 'SCALAR');
    return $current;
}

fixes this.

(Continue reading)

Jean-Michel Hiver | 20 Jul 10:13

Re: cont'd: Dereferencing SCALAR references correctly

> Changing the last part of Petal/Hash/Var.pm to
> 
>     # return '' unless (defined $current);
>     # $current = "$current" if (defined $current);
>     return $$current if isa($current, 'SCALAR');
>     return $current;
> }
>                                                                                                     
> fixes this.

Ah cool. I like fixes ;-)

I'll put it in for the next version of Petal.

Kevin Teague | 21 Jul 23:30
Picon
Favicon

tal/petal naming bug?

Is the following a known bug in Petal?

<html>
<body>
   <div metal:use-macro="foo.pt#bar" />
</body>
</html>

And then within the foo.pt macro:

<div metal:define-macro="bar">
   <p tal:content="somevar" />
   <p metal:content="somevar" />
</div>

Only the second paragraph works, it seems that within a macro Petal only 
recognizes the "petal:" syntax and not the "tal:" syntax.

Also, thanks for implementing the metal:define-macro and metal:use-macro 
functions, these make writting larger TAL sites much nicer.

  - Kevin Teague
    Web Developer
    Canada's Michael Smith Genome Sciences Centre

Jean-Michel Hiver | 22 Jul 04:41

Re: tal/petal naming bug?

Kevin Teague wrote:
> Is the following a known bug in Petal?
> 
> <html>
> <body>
>   <div metal:use-macro="foo.pt#bar" />
> </body>
> </html>
> 
> And then within the foo.pt macro:
> 
> <div metal:define-macro="bar">
>   <p tal:content="somevar" />
>   <p metal:content="somevar" />
> </div>

metal:content will *not work*...

> Only the second paragraph works, it seems that within a macro Petal only 
> recognizes the "petal:" syntax and not the "tal:" syntax.
> 
> Also, thanks for implementing the metal:define-macro and metal:use-macro 
> functions, these make writting larger TAL sites much nicer.

from 'perldoc Petal'

   NAMESPACE

   Although this is not mandatory, Petal templates should include use the
   namespace http://purl.org/petal/1.0/. Example:
(Continue reading)

Jean-Michel Hiver | 22 Jul 16:25

Petal 2.10 Released

Hi Gang,

I just realized that I forgot to apply Warren's patch... doh... for the 
next release I promess...

Anyway good news is, I have *experimental, api is subject to change* 
ZPT-like i18n support, and although the implementation is not complete, 
it seems to work pretty well :-)

i18:domain is supported but Petal does nothing special with them (maybe 
it should?)

i18n:translate and i18n:name are fully supported.

Consult Petal::I18N to see how it works.

If anybody on the list is familiar with gettext(), I could do with a 
critical view on the work. Sometime I've felt I didn't really know what 
I was doing :-/

I also tidied up the docs a bit (moved a lot of old backwards 
compatibility stuff in Petal::Deprecated to keep the size of the docs 
down) and added some tests, which never hurts.

So that's it... Petal = Perl TAL + METAL + I18N. All in one big hacky 
module. Yey!

Maybe we should rename the module PeMeTALi18n ;-)

Happy hacking!
(Continue reading)

Chris Croome | 23 Jul 12:48
Picon
Favicon

Fedora RPMs, was: Re: Petal 2.10 Released

Hi

I have build some Fedora Core 2 RPMS (they also seem to work OK on FC1),
add this to you apt sources.list to try them:

  rpm http://rpms.mkdoc.com/pub/apt fedora/linux/2/i386 mkdoc 
  rpm-src http://rpms.mkdoc.com/pub/apt fedora/linux/2/i386 mkdoc 

There is a bit more info here:

  http://rpms.mkdoc.com/

I _wouldn't_ recomend these for use on a production server, but they are
handy for dev machines like desktops.

Chris

--

-- 
Chris Croome                               <chris@...>
web design                             http://www.webarchitects.co.uk/ 
web content management                               http://mkdoc.com/   

Jean-Michel Hiver | 23 Jul 14:17

Petal 2.11 released

Revision history for Petal.

2.11 Fri Jul 23 13:10:30 2004
    - Applied Warren Smith's dereferencing patch
    - Fixed broken tests for I18N


Gmane