<html>
<body>
At 06:56 PM 4/20/2005, PFraterdeus wrote:<br>
<blockquote type=cite class=cite cite="">Here'a little py script for a
plone page template...<br>
I just want to translate the 'key' (organicnews) to a 'value' (Organics
in the<br>
News), for presentation purposes. (the key, of course, is in the URL
request)<br><br>
<br>
db = request.db<br><br>
if db=="organicnews": <br>
print "%s" % html_quote('Organics in the News')<br>
elif db=="ovnews":<br>
print "%s" % html_quote('Our Stuff in the News')<br>
elif db=="pressreleases":<br>
print "%s" % html_quote('Press Releases')<br>
else:<br>
print "Unknown News Database!",<br>
print "%s" % db<br>
return printed</blockquote><br>
Use a dictionary:<br><br>
responses = {"organicnews": "Organics in the News'",
"ovnews" : "'Our Stuff in the News'",
"pressreleases" : "'Press Releases'"}<br>
print html_quote(responses.get(db, "Unknown News Database! " +
db))<br><br>
BTW there is no benefit to print '%s' % blahblah. print blahblah does the
same thing.<br><br>
<blockquote type=cite class=cite cite="">[snip]<br>
I know there's a proper way to do this with a tuple, or something
:)<br>
For the three values, it's not a problem, but if I want to scale up to
many, I<br>
imagine the dictionary is the way to go...</blockquote>
<x-sigsep><p></x-sigsep>
<font size=2>Bob Gailer<br>
<a href="mailto:bgailer@alum.rpi.edu" eudora="autourl">mailto:bgailer@alum.rpi.edu<br>
</a>510 558 3275 home<br>
720 938 2625 cell</font> </body>
</html>