[Zope] DTML to ZPT code question

Paul Winkler pw_lists at slinkp.com
Tue Dec 28 13:18:05 EST 2004


On Tue, Dec 28, 2004 at 12:39:11PM -0500, Allen Schmidt wrote:
> <dtml-if "fredsession.getsessionuser()!='no session'">
> 	Hello, <dtml-var "fredsession.getsessionuser()">
> 	(<a href="/fredsession/logout?return_to_page=<dtml-var 
> 	"_.string.split(URL,'//')[1]" missing="index_html" null="index_html">
> 		<dtml-if QUERY_STRING>?<dtml-var QUERY_STRING></dtml-if>">   
> 		click here to logout</a>)
> 
> ...other stuff if logged in...
> 
> </dtml-if>
> 
> 
> I have only started looking at the page that has this code to convert to 
> ZPT (of which I am really starting to enjoy) but wondered if anyone had a 
> quick example of how to handle the splitting of the URL in a TAL statement 
> and the forming of the href attribute of that anchor tag.

Well, that's kinda messy, and there's enough going on in that <a> tag
that I'd be tempted to factor it out into a script.
Something like (untested):

(<a tal:attributes="href string:/fredsession/logout?return_to_page=${context/get_path_and_query}">
    Click here to logout
</a>)

... and the accompanying script (untested, but should be equivalent to your
DTML code):

request = context.REQUEST
url = request.get('URL')

if url is None:
    path = 'index_html'
else:
    path = url.split('//')[1]

query = request.get('QUERY_STRING', '')
if query:
    query = '?' + query

return path + query

-- 

Paul Winkler
http://www.slinkp.com


More information about the Zope mailing list