[Zope] another simple one
Eric Walstad
eric@ericwalstad.com
Wed, 20 Feb 2002 11:07:50 -0800
Hi Rick,
I think that something like this will work for you:
<dtml-call expr="REQUEST.set('ListContainingSplitItems',
_.string.split(VariableNameToSplit, '-')">
This sets a variable in the REQUEST dictionary by first calling the
split function of the string module. The ListContainingSplitItems
variable will contain the results of your call to split(). The
"VariableNameToSplit" variable is the one that contains the "108243-132"
string.
Then you can iterate through your split items with
<dtml-in ListContainingSplitItems>
<!-- Do something useful here -->
Item #<dtml-var sequence-index> is <dtml-var sequence-item>
</dtml-in>
Search the archives or look in your Zope book for info on "_" (the
underscore), which has special meaning in Zope.
I would recomend that you do this sort of thing with a Python Script
instead of DTML. I think it's cleaner than the messy DTML above.
Script (Python) Id = split_on_hyphen
parameters VariableNameToSplit
import string
return string.split(VariableNameToSplit, '-')
Then your dtml would look like this:
<dtml-in "split_on_hyphen(VariableNameToSplit)">
<!-- Do something useful here -->
Item #<dtml-var sequence-index> is <dtml-var sequence-item>
</dtml-in>
Hope that helps,
Eric.
D. Rick Anderson wrote:
> I need to split a variable out into two parts. The variable looks like
> this: 108243-132 and I need to split it where the - is. I can do this easy
> enough in Perl but this Zope server happens to be on a Wintendo 2000 box
> and I haven't been able to get perl working correctly with Zope. Is there
> an easy way to split a variable with dtml?
>
> "The Zope Book" that I bought doesn't seem to cover any of this, or it
> does in such an obscure way that I can't find what I'm looking for. It's
> been a great book to start with, but I need something that's a little more
> in depth. I've seen a few more books on Amazon and I'm thinking about
> buying the Zope Bible to keep me busy until Dieter's book comes out. Does
> anybody have any suggestions?
>
> Rick