Thedi Gerber | 21 Aug 07:48
Picon

Bug report: Dollar follwed by a name gets lost

We are currently starting a new project and would like to use Petal. While doing some exercises to 
get to know it, i tried to include a small example perl script in a template. To my surprise, 
variable names in the perl source were lost.

After some more tests, I came to this conclusion:

$variable                         IN THE template magically disappears
$1000                             is ok
$n                                is ok (single letter following a $)
<span tal:content="xx">...</span> replaces the content always ok

Here is a small example:

---------------------------------- my template:
<html xml:lang="en"
lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://purl.org/petal/1.0/">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"/>
</head>
<body>

<p>
10 dollars are <b>$10</b>, n dollars are <b>$n</b>,
but nn dollars disapear <b>$nn</b>!
</p>

</body>
</html>
(Continue reading)

Mark Holland | 21 Aug 11:09

Re: Bug report: Dollar follwed by a name gets lost

On 21/08/08 06:48, Thedi Gerber wrote:
> We are currently starting a new project and would like to use Petal. 
> While doing some exercises to get to know it, i tried to include a small 
> example perl script in a template. To my surprise, variable names in the 
> perl source were lost.
> 
> After some more tests, I came to this conclusion:
> 
> $variable                         IN THE template magically disappears
> $1000                             is ok
> $n                                is ok (single letter following a $)
> <span tal:content="xx">...</span> replaces the content always ok

Petal is interpolating $variable with parameters passed through 
->process(). If you were to pass through 'variable' as a argument you 
would see it printed. ($1000 and $n are not regarded as valid variable 
names).

E.g. if you were to change the following in your example:
   my %content_data = (nn => 'foo');
   my $task_result = $task->process( \%content_data );

you will see the output:

   "but nn dollars disappear <b>foo</b>!"

I've forgotten if there's a proper way to escape dollar characters in 
Petal, but one work around would be to use html entites, e.g.:

   This costs &#36;45
(Continue reading)


Gmane