By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,937 Members | 1,411 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,937 IT Pros & Developers. It's quick & easy.

select options with PSP template

P: n/a
Can someone give an opinion whether this is a dumb approach?

I want to generate a list of OPTION elements for s SELECT element, but
I can't see any (clean) way to use a template on a list of values
(other than building HTML outside of the template, which is what I'm
trying to avoid). This is what I came up with.

It uses three template files and the .py file. The trick (for lack of a
better word) is to nest a template inside of itself. Looks a little
lispish to me :^)

It might not be a good idea for really long lists, but a SELECT
shouldn't have all that many options anyway.

########## index.py ##########
from mod_python import psp

def test(req):
...
...nested =''
...
...for x in range(10):
.....nested = psp.PSP(req, filename='opt2.tmpl',
......................vars={'val1': nested,
............................'val2': psp.PSP(req, filename='opt.tmpl',
............................................vars={ 'val':x})})
...tmpl = psp.PSP(req, filename='seltest.tmpl')
...tmpl.run(vars = {'options': nested})
...return
######## seltest.tmpl ###########
<html>
<h2>Test of Select</h2>
<select>
<%= options %>
</select>
</html>

######### opt2.tmpl ###########
<%= val1 %>
<%= val2 %>

######### opt.tmpl ############
<option><%= val %></option>

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.