Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > select options with PSP template

Reply
Thread Tools

select options with PSP template

 
 
tomhath
Guest
Posts: n/a
 
      12-13-2004
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'})})
...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>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PSP News. Working PSP Firmware 2.0 to 1.50 Downgrader!!! XP NZ Computing 0 09-28-2005 09:01 AM
PSP / mod_python ... how to get POST vars on .psp ? Rod Castellanos Python 1 06-07-2005 03:27 AM
PSP / mod_python ... how to get POST vars on .psp ? Rod Castellanos Python 2 06-07-2005 02:34 AM
Hey, Free Sony PSP. Best thing since sliced bread! It's So easy,and 100% legal! GET A FREE SONY PSP! !!NO CATCH!! Sarah Stewart Computer Support 0 05-08-2005 08:47 AM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM



Advertisments