roller-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Allen Gilliland <allen.gillil...@sun.com>
Subject Re: Roller 3.0 macros and JavaScript
Date Wed, 06 Sep 2006 22:34:00 GMT
your problem on this one is that you want to get the url when the 
javascript is executed, not when the template is being rendered, and you 
are mixing the two contexts.  this is a general timeline of when things 
would be executed ...

browser sends request
   roller gets request
     roller does template rendering
   roller returns html
browser gets response
   browser executes javascript
browser done rendering

when you have $url.category("catname") in your templates, that is a 
velocity call which happens during template rendering.  so you need to 
have a real value for that call at that time.

unfortunately, there isn't really a way to provide a javascript widget 
access to velocity functions run during the rendering process, but there 
are 2 ways to could deal with this.

1. build a map of all your category links during rendering, then access 
that map as javascript when your js function is called.  basically you 
would be building your javascript function at template rendering time.

2. do like you had done in your old function and just piece together the 
url yourself ...

#set( $blogURL = "$url.home" )
if (catname == "All" ) {
       url="$blogURL" }
else {
       url="$blogURL/category/"+catname
}

-- Allen


sharps wrote:
> Bear with me - it's been a while since I hacked JavaScript.
> 
> Pre Roller 3.0 I had some JavaScript :
> 
> function selectCategory(catname) {
>    var url;
>    #set( $blogURL = "$baseURL/page/$userName" )
>    if (catname == "All" ) {
>       url="$blogURL" }
>    else { 
>       url="$blogURL/?catname=/"+catname 
>     }
>     window.location.replace ( url ); 
> }
> 
> using the new macros I should use :
> 
> url="$url.category (catname)"
> 
> unfortunately that doesn't work - maybe something to do with the evaluation
> order ?
> 
> Any ideas how to code such an expression ?

Mime
View raw message