As a stopgap, this might work (untested -- I don't have an installation at home):
<img tal:define="url python: event['Image'] and event['Image']['URL'];"
tal:condition="python: event['Image']"
tal:attributes="src python: url if url.startswith('http') else 'http://events.foo.edu%s' % (url,);
alt python: event['Title'];
width string:40px " /></a>
(Note that your code doesn't handle event['Image']
not having an entry URL
, neither does mine.)
There's probably a more elegant solution to be had using urlsplit
/urljoin
, though, which would dissect your url into protocol, server, path, query, fragment, and you could reassemble it from there.
In detail, we define a variable url
to save ourselves a bit of typing -- we first have to check again that event['Image']
is present. The whole tag is protected by a tal:condition
that does this, but the order of execution is always define
, condition
, repeat
, content
/replace
, attributes
, omit
; this is so you can define a variable and use it in the condition clause. We could name it URL
, but I don't usually name my variables in all-caps. x and y
in python yields the value of x
if it is falsy and the value of y
if it is truthy, so in the usual case, we'll get the url-ish string from your object.
The new attributes clause might be confusing because it's underparenthized: in more detail, it's
url if url.startswith('http') else ('http://events.foo.edu%s' % (url,));
so it's the usual string formatting. Seeing how the %s
is at the end, we coud probably say 'http://events.foo.edu'+url
, but "don't concatenate constants and user data together" triggers my "is this a possible command injection vulnerability" reflex.