[Plone-UI] Page template needs gif used to be conditional of the current path

Veda Williams veda at onenw.org
Wed Sep 3 17:15:50 UTC 2008


That's funny, I was just going to blog about this. Here's a little snippet
or two that might help:

<!-- this snippet looks up to the root and finds an image there called
section-top.jpg -->

<img src="" id="section-top"
    tal:define="portal_url context/@@plone_portal_state/portal_url;"
    tal:attributes="src string:$portal_url/section-top.jpg"
    alt="Background image" />

<!-- this snippet looks in your current context and finds an image called
section-top.jpg; if there's nothing there, it displays nothing and doesn't
error out -->

<img src="" tal:define="img nocall:context/section-top.jpg"
            tal:attributes="src img/absolute_url"
            tal:on-error="nothing"
            alt="background image"/>
            
We use nocall because you have to do that if you give a path expression to a
real object (as opposed to a method on an object, which is more normal), or
else zope will publish it and you'll get the rendered HTML for the page for
viewing that object, which is quite ugly.

In this particular case, at the root of your site you'd add a fallback image
named section-top.jpg, and elsewhere in the site you can add different
images. If there isn't a section-top.jpg in a given section, it'll default
to the one at the root. They both should be named the same, btw.

This doesn't suit your use case, but is an interesting approach I use quite
frequently:

http://www.aclark.net/Members/aclark/placeful-theming/

          





On 9/3/08 6:02 AM, "treid" <anthonyfreid at gmail.com> wrote:

> 
> Hello
> 
> I have a viewlet page template called portal_bottom.pt that calls gif for
> display.
> 
> I would like the gif used to be conditional of the current path.
> 
> So if the URL starts with "domain.com/special-path" I would like the image
> to be displayed "image-b.gif" otherwise I would like the image to be
> "image-a.gif"
> 
> img src="/path/to/graphic/image-" if URL starts with "/special-path" "b.gif"
> else "a.gif"  ...
> 
> I'm guessing a little python is needed here but I don't know python so could
> someone help me out please?
> 
> Thanks
> 
> Tony 





More information about the UI mailing list