[Petal] Javascript and CSS

Josh Narins josh at narins.net
Tue Oct 11 16:44:13 BST 2005


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) {
>       window.alert("HI");
>    }
> 
>    // -->
> </script>
> 
> However, if you want to interpolate variables into js, you will have to 
> do something like this:
> 
> <script>
>    var a = "${a}";
>    var b = "${b}";
> 
>    // <!--
> 
>    if(a < b) {
>       window.alert("HI");
>    }
> 
>    // -->
> </script>
> 
> Hope this helps,
> 
> -Warren
> Josh Narins wrote:
> 
> >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
> > 
> >
> 


More information about the Petal mailing list