[Zope] DTML to ZPT code question

Allen Schmidt aschmidt at fredericksburg.com
Tue Dec 28 13:40:49 EST 2004


Excellent!

Thanks Paul! I will give that a shot. Looks logical enough! :)

Our entire Zope life has been lived in DTML. Never a reason to switch. Others have done more with py scripts but now I am venturing into page templates more and the absolute need to do more in py scripts. TAL is slick but I still stumble on old DTML embedded 'logic' that I will have to move out to py and then call from tal.

Thanks again

Allen



Paul Winkler wrote:

> 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
> 


More information about the Zope mailing list