Josh Narins | 11 Oct 16:09

Javascript and CSS

Going to do some dynamic javascript, where the function itself is
dynamic, and CSS is basically the same question.

The big question is basically the <!-- and --> which properly goes
around the CSS and javascript for "older" browers.

That wouldn't happen here.

# set the javascript using perl
$tal->{javascript} = "function a(obj) { ... stuff ... }";

#template contains
<script type="text/javascript" petal:content="/javascript" />

Has anyone ever tried anything like this, with javascript, either?
Again, no <!-- and --> will work.

<style type="text/css">
  .classA { <span petal:replace="/usr/style_config/classA" /> }
  .classB { color: blue; }
</style>

Cheers,
Josh

Warren Smith | 11 Oct 16:31

Re: Javascript and CSS

Josh,

That will work if you do <script petal:content="structure /javascript" />.
The structure tag tells TAL to not parse out html entities (<>, etc)

However, petal will give you some problems if you do something like this:

<script>
    if(a < b) {
       window.alert("HI!");
    }
</script>

Petal has some intelligence built in so you can do:

<script>

    // <!--

    if(a < b) {
       window.alert("HI");
    }

    // -->
</script>

However, if you want to interpolate variables into js, you will have to 
do something like this:

<script>
(Continue reading)

Josh Narins | 11 Oct 17:44

Re: Javascript and CSS

Helped a lot, thanks.

This seems like appropriate cookbook material, imho.

The trick with the // <!-- and non-interpolation of variables therein
especially.

Cheers,
Josh

> Josh,
> 
> That will work if you do <script petal:content="structure /javascript" />.
> The structure tag tells TAL to not parse out html entities (<>, etc)
> 
> However, petal will give you some problems if you do something like this:
> 
> <script>
>    if(a < b) {
>       window.alert("HI!");
>    }
> </script>
> 
> Petal has some intelligence built in so you can do:
> 
> <script>
>   
>    // <!--
> 
>    if(a < b) {
(Continue reading)

Josh Narins | 14 Oct 18:43

Auto omit-tag

I tend to use the same tag, over and over, to identify to me that I am
going to omit the tag (petal:omit-tag="string:1"). I generally use
tables and not divs, so if I see <div>, I know there is an omit-tag at
the end.

Any chance there could be a feature that automatically omitted a
specified tag? <omit petal:condition="">, for example.

I use them for control structures, like repeats and conditions.

Not a huge deal, but it might be nice.

-Josh

Warren Smith | 14 Oct 21:17

Re: Auto omit-tag


Petal only understands attributes and not tags (I think). There are a 
couple of options to save typing:

1. Put this as part of your root tag:

<html xmlns:tal="http://purl.org/petal/1.0/">
Then you can type tal: instead of petal:

2. use <tag tal:replace="path/to/var"></tag> this will replace the 
entire tag with the value of path/to/var

3. Technically <tag tal:omit-tag=""></tag> will eliminate the tag. It's 
not in the spec, but saves typing.
4. Use the shorthand ${path/to/var}. It violates some of the principals 
of Petal, but is rather handy.

Hope this helps,

Warren

Josh Narins wrote:

>I tend to use the same tag, over and over, to identify to me that I am
>going to omit the tag (petal:omit-tag="string:1"). I generally use
>tables and not divs, so if I see <div>, I know there is an omit-tag at
>the end.
>
>Any chance there could be a feature that automatically omitted a
>specified tag? <omit petal:condition="">, for example.
(Continue reading)

Warren Smith | 14 Oct 21:20

Re: Auto omit-tag

*sigh*

My High School English Teacher would kill me for that grammar.

s/principal/principle/;

-Warren

Warren Smith wrote:

>
> Petal only understands attributes and not tags (I think). There are a 
> couple of options to save typing:
>
> 1. Put this as part of your root tag:
>
> <html xmlns:tal="http://purl.org/petal/1.0/">
> Then you can type tal: instead of petal:
>
> 2. use <tag tal:replace="path/to/var"></tag> this will replace the 
> entire tag with the value of path/to/var
>
> 3. Technically <tag tal:omit-tag=""></tag> will eliminate the tag. 
> It's not in the spec, but saves typing.
> 4. Use the shorthand ${path/to/var}. It violates some of the 
> principals of Petal, but is rather handy.
>
> Hope this helps,
>
> Warren
(Continue reading)

Jonathan | 15 Oct 04:10

Re: Auto omit-tag


that could be cool for petal... but it could cause a lot more  
problems -- petal would understand it, while other TAL  
implementations probably wouldn't - so your TAL documents wouldn't be  
portable.

On Oct 14, 2005, at 12:43 PM, Josh Narins wrote:

> Any chance there could be a feature that automatically omitted a
> specified tag? <omit petal:condition="">, for example.

Josh Narins | 18 Oct 22:36

Calling template?

Can I determine which template is calling the one I am in?

I have a shared component, I can get around it, but was just wondering.

tia,
Josh

Jonathan | 26 Oct 17:33

Interpolating Form Data Tactic


I've settled on a standard method that i've found super comfortable  
for interpolating form data with static TAL files.

Just wanted to share it with the list, as a few friends who tried  
this really liked this way of setting up data structure for  
interpolation and have adopted it  too.

I create a 'Defaults' data structure for the form data with _checked,  
_text and _selectxml/_selected sub-structures to  handle form info  
based on the type

the _selectxml data is not processed in tal, it easily could be -- i  
just had already written a bunch of routines that already did that  
stuff outside of tal.

anyways, the perl looks like this:

my %Defaults'     =
(
     '_checked'     =>
     {
         'fieldname' =>
         {
             'fieldvalue' => 'checked'
         }
     }
     ,
     '_text' =>
     {
(Continue reading)

Jonathan | 29 Oct 00:48

false:EXPRESSION vs not:EXPRESSION


is there any reason why petal uses false:EXPRESSION instead of  
not:EXPRESSION ( which is the way TAL is originally implemented) ?

it's easy to work around this, either with using 'false' in the  
templates or extending petal with a modifier to recognize 'not'

i understand the need for a perlish true/false vs the pythonic not --  
i'm just wondering why petal doesn't support it with an alias so that  
templates originally written for python or another implementation  
will work right out of the box.


Gmane