On Wednesday, May 25, 2011 12:40:30 PM UTC-7, Geoff wrote:
>
> On May 25, 5:16 pm, Wyatt Baldwin <[email protected]> wrote: 
> > On Wednesday, May 25, 2011 5:51:15 AM UTC-7, Geoff wrote: 
> > 
>
> > 
> > In your templates, use the `pylons.url` function to generate URLs: 
> > 
> > ${url('/css/blah.css')} 
> > 
> > Pass the app prefix through to your JS, perhaps like this: 
> > 
> > <script> 
> >     my_namespace.app_prefix = '${url("/")}'; 
> >     var url = [my_namespace.app_prefix, '/some/path'].join('/');  // 
> maybe 
> > create a utility function for this 
> > </script> 
> > 
>
> Unfortunately I have not found a way to put one expression 
> substitution inside another and my templates have this sort of thing: 
>
> ${h.stylesheet_link('/css/main.css')} 
>
> It would be nice to do this: 
>
> ${h.stylesheet_link(${url('/css/main.css')})} 
>
> but, alas, this doesn't work. 
>

The stuff inside ${} is plain Python. Your example will work if you change 
it to this:

${h.stylesheet_link(url('/css/main.css'))} 
 
 

> Also my js files are separate from the template so the url function 
> isn't available. 
>

If you set the prefix as a JS var in your template before the <script>s that 
load the rest of your JS files, you will be able to access it in your other 
scripts.

 

> > If you are running your app behind a proxy, you will need to use 
> something 
> > like Paste's PrefixMiddleware. 
>
> This is the answer! As described at 
> http://pythonpaste.org/deploy/modules/config.html 
> I have added the prefix filter to development.ini and now I can prefix 
> all my static paths with the appropriate string. As long as I do not 
> carry this over to production.ini then it should work fine. 
>

You really should use the `url` function as described above. It will make 
your life much easier. 

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to