hi, I've just learned my DTML-lesson... Don't use DTML for any program-logic!!! Not even the small bits... Debuged 3 hours... if've used this snippet for months and it worked well... <dtml-return "_['title'][_['title'].find('#')+1:]"> today it stopped working with an "access denied"-error... don't ask why... I've no idea, but maybe I've touched a guarded-namespace... typical DTML-mystery. this python one works well: return context.title[context.title.find('#')+1:] ergo: don't use DTML for logic, use Python! maybe: don't use DTML for presentation, use ZPT [I'm not totally convinced of that by now, but especially for Chris W.: maybe I will following your ZPT-church in the near future too...;-)] cheers, maik -- Maik Jablonski __o www.zfl.uni-bielefeld.de _ \<_ Deutsche Zope User Group Bielefeld, Germany (_)/(_) www.dzug.org
and still another lesson... python this time. it's my learning day today. ;-) **explicit is better than implicit!** IMPLICIT [no checks at all => that's the dark side of coding]: return context.title[context.title.find('#')+1:] BETTER: title=context.getProperty('title') if title<>'': pos = title.find('#') if pos<>-1: return title[pos+1:] return title that's enough for today. cheers, maik Maik Jablonski wrote:
hi,
I've just learned my DTML-lesson... Don't use DTML for any program-logic!!! Not even the small bits...
Debuged 3 hours...
if've used this snippet for months and it worked well...
<dtml-return "_['title'][_['title'].find('#')+1:]">
today it stopped working with an "access denied"-error... don't ask why... I've no idea, but maybe I've touched a guarded-namespace... typical DTML-mystery.
this python one works well:
return context.title[context.title.find('#')+1:]
ergo: don't use DTML for logic, use Python!
maybe: don't use DTML for presentation, use ZPT [I'm not totally convinced of that by now, but especially for Chris W.: maybe I will following your ZPT-church in the near future too...;-)]
cheers, maik
-- Maik Jablonski __o www.zfl.uni-bielefeld.de _ \<_ Deutsche Zope User Group Bielefeld, Germany (_)/(_) www.dzug.org
On Tue, Aug 20, 2002 at 02:21:23PM +0200, Maik Jablonski wrote:
<dtml-return "_['title'][_['title'].find('#')+1:]">
today it stopped working with an "access denied"-error... don't ask why... I've no idea, but maybe I've touched a guarded-namespace... typical DTML-mystery.
this python one works well:
return context.title[context.title.find('#')+1:]
You're trying to print everything in the title after a "#" character? I think this is a little more "pythonic", at least to me the intent is easier to see: return context.title.split('#')[1] ... but it's just a matter of style. -- Paul Winkler "Welcome to Muppet Labs, where the future is made - today!"
On Tue, Aug 20, 2002 at 07:01:02AM -0700, Paul Winkler wrote:
return context.title.split('#')[1]
... and to follow up on your latest discovery - always do error checking - I'd do it like this: try: title_parts = context.title.split('#', maxsplit=1)[1] return title_parts[1] except IndexError: # there is no '#' in the title return title -- Paul Winkler "Welcome to Muppet Labs, where the future is made - today!"
hi paul, thank you for the hints... that's the way I will do the stuff in future. I've eaten to much C in my younger years, I guess.;-) cheers, maik Paul Winkler wrote:
On Tue, Aug 20, 2002 at 07:01:02AM -0700, Paul Winkler wrote:
return context.title.split('#')[1]
... and to follow up on your latest discovery - always do error checking - I'd do it like this:
try: title_parts = context.title.split('#', maxsplit=1)[1] return title_parts[1]
except IndexError: # there is no '#' in the title return title
--
Paul Winkler "Welcome to Muppet Labs, where the future is made - today!"
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Maik Jablonski __o www.zfl.uni-bielefeld.de _ \<_ Deutsche Zope User Group Bielefeld, Germany (_)/(_) www.dzug.org
Am Die, 2002-08-20 um 16.28 schrieb Paul Winkler:
On Tue, Aug 20, 2002 at 07:01:02AM -0700, Paul Winkler wrote:
return context.title.split('#')[1]
... and to follow up on your latest discovery - always do error checking - I'd do it like this: What about this (no try/except): (title_parts.split("#",1)*2)[1]
Another trick to avoid IndexErrors in python is slicing: Instead of: try: x=a[1] except IndexError: x=None one can write: x=(a[1:1]+[None,])[0] Andreas
try: title_parts = context.title.split('#', maxsplit=1)[1] return title_parts[1]
except IndexError: # there is no '#' in the title return title
--
Paul Winkler "Welcome to Muppet Labs, where the future is made - today!"
Hi I use pagetemplates almost to the exclusion of dtml with only a few exceptions. I find with pagetemplates that if you have large chunks of Javascript, that need to be dynamically modified that pagetemplates requirement to validate the page becomes a pain. You get situations within Javascript where to get the page to compile, you have to do really ugly hacks, which quickly become even more unreadable than dtml dtml is also just so much more forgiving if you don't want a page that is not html/xml oriented. So I say keep dtml in you toolbox of tricks See ya Tim On Tue, 2002-08-20 at 20:21, Maik Jablonski wrote:
hi,
I've just learned my DTML-lesson... Don't use DTML for any program-logic!!! Not even the small bits...
maybe: don't use DTML for presentation, use ZPT [I'm not totally convinced of that by now, but especially for Chris W.: maybe I will following your ZPT-church in the near future too...;-)]
On Wed, Aug 21, 2002 at 10:06:46AM +0800, Tim Hoffman wrote:
I find with pagetemplates that if you have large chunks of Javascript, that need to be dynamically modified that pagetemplates requirement to validate the page becomes a pain. You get situations within Javascript where to get the page to compile, you have to do really ugly hacks, which quickly become even more unreadable than dtml
Out of curiosity, is this pain at all reduced if you put the Javascript in some other page and refer to it from your templates? Or is Javascript not similar enough to valid xml in general? -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University -- renfro@tntech.edu
[Mike Renfro]
On Wed, Aug 21, 2002 at 10:06:46AM +0800, Tim Hoffman wrote:
I find with pagetemplates that if you have large chunks of Javascript, that need to be dynamically modified that pagetemplates requirement to validate the page becomes a pain. You get situations within Javascript where to get the page to compile, you have to do really ugly hacks, which quickly become even more unreadable than dtml
Out of curiosity, is this pain at all reduced if you put the Javascript in some other page and refer to it from your templates? Or is Javascript not similar enough to valid xml in general?
Can you use CDATA sections in page templates (I would think you should be able to)? If so, those large chunks of javascript can mostly go into CDATA sections. This is a common approach to including javascript in xslt templates. Cheers, Tom P
Am Mit, 2002-08-21 um 17.16 schrieb Mike Renfro:
On Wed, Aug 21, 2002 at 10:06:46AM +0800, Tim Hoffman wrote:
I find with pagetemplates that if you have large chunks of Javascript, that need to be dynamically modified that pagetemplates requirement to validate the page becomes a pain. You get situations within Javascript where to get the page to compile, you have to do really ugly hacks, which quickly become even more unreadable than dtml
Out of curiosity, is this pain at all reduced if you put the Javascript in some other page and refer to it from your templates? Or is Javascript not similar enough to valid xml in general? Nope it is not. As most programming languages are ;) But the solution is quite easy. Stuff your dynamic Javascript into a DTML Method, and include it from the page template.
Andreas
participants (6)
-
Andreas Kostyrka -
Maik Jablonski -
Mike Renfro -
Paul Winkler -
Thomas B. Passin -
Tim Hoffman