|
Julien Cigar
jcigar at ulb.ac.be
Mon Jun 12 08:55:57 EDT 2006
Hello list,
I have a little problem with psp (I'm using psp as a template engine)
In one of my templates I have :
<input type="text" class="scientific_name" name="scientific_name"
value="<%= invasive.scientific_name %>" />
The problem I have is that I'm using this form in different context and
sometimes the 'invasive' object doesn't exists.
Is there a way to "display-only-if-object-exist" ? What I would like to
avoid is things like :
<%
try:
# BEGIN
%>
<%= invasive.scientific_name %>
<%
#END
except:
#BEGIN
%>
blabla
<%
# NED
%>
I tried something like :
def show_if_defined(s, obj=globals()):
for part in s.split('.') :
if not hasattr(obj, part):
return ''
obj = getattr(obj, part)
return obj
and
<input type="text" class="scientific_name" name="scientific_name"
value="<%= show_if_defined('invasive.scientific_name') %>" />
but without success ...
Any idea ?
Thanks
--
Julien Cigar
Belgian Biodiversity Platform
http://www.biodiversity.be
Université Libre de Bruxelles
Campus de la Plaine CP 257
Bâtiment NO, Bureau 4 N4 115C (Niveau 4)
Boulevard du Triomphe, entrée ULB 2
B-1050 Bruxelles
office: jcigar at ulb.ac.be
home: mage at mordor.ath.cx
|