[Petal] Looping through a hash

William McKee william at knowmad.com
Fri Sep 5 04:58:31 BST 2003


On Thu, Sep 04, 2003 at 05:10:20PM +0100, Steve Purkis wrote:
> You could write a modifier, and use it with petal:repeat:

Thanks Steve! That's what I needed.


> And then:
> 	<span petal:repeat="key keys: $some_hash">
> 		do something with $key ...
> 	    will this get the value: ${some_hash/$key} ?
> 	</span>

Nice try but Petal isn't getting the value. I tried various
modifications but Petal doesn't want to allow the dynamic key. Could one
of the Petal engine experts comment on this?

While we are on the topic of the Petal engine, I'm trying to pass a
string value in as a parameter to one of my modifiers. Is this allowed?
What I'm trying to do is allow an arbitrary string to be the date
separator. So my proposed modifier would be called as follows:
	<p tal:content="us_date: $date -">date</p>

This gives me several interesting errors. I tried putting the - in
single quotes and prefixing it with string: but neither worked. I also
tried defining a variable but apparently I can't set a variable to a
string (or I'm not doing it right). Am I missing something or is this
just not possible?


> If you want both a list of key/value pairs, you could write 
> Petal::Hash::Each to do something like:

Ahh, another approach! And this one works for retreiving the values.


> I've got a few little plugins like this that might be good candidates 
> for a Petal::Utils package at some stage.

Building a utils package has been on my to do list for several months
now, so I used this opportunity to actually build it and combine several
of my modifiers. Since you had the idea first, would you like to create
it and put it onto CPAN?

I have attached a tarfile of my initial version since it's less than 4K.
Comments appreciated. The broken tests have been commented out in the
01.t file.


Many thanks!
William

-- 
Knowmad Services Inc.
http://www.knowmad.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Petal-Hash-Utils-0.01.tar.gz
Type: application/octet-stream
Size: 3739 bytes
Desc: not available
Url : http://lists.webarch.co.uk/pipermail/petal/attachments/20030905/f2df2bf6/Petal-Hash-Utils-0.01.tar.obj


More information about the Petal mailing list