Thank you very much for your answers.

 

I've tested your suggestion already (I suppose, it was your answer in
some other thread), assuming it should work, but I'm afraid it doesn't.
Hopefully, it is because .list is just another VMethod. If you test it
in my code from previous message (it should be run-able as is, just copy
and paste), you get similar output (not very same) as before. On 6th
line of output now you get:

 

6 Sorted array of 1 MyObj item    : MyObj=HASH(0x1c57ebc) ->
HASH(0x1c601cc) =   HASH(0x1c57dac) =  

instead of previous

6 Sorted array of 1 MyObj item    : MyObj=HASH(0x1c57c2c) ->  foo =
name =  

whereas correct should be (as demonstrated on line 3)

6 Sorted array of 1 MyObj item    : MyObj=HASH(0x1c57c2c) ->
MyObj=HASH(0x1c5bd34) = a

 

This is respectively because:

[% your_function.list.sort %] produces list of hashes of object's
attributes: ( {'key' => 'foo', 'value' => undef}, {'key' => 'name',
'value' => 'a'} )

instead of previous

[% your_function.sort %] produces list of object's attributes: ('foo',
'name')

whereas correct product should be the object:

MyObj=HASH(0x1c5bd34)

 

I look forward to your answer,

PD

 

 

-----Original Message-----
From: Andy Wardley [mailto:[email protected]] 
Sent: Thursday, December 10, 2009 1:21 PM
To: Danihlik Petr PLZ ELD
Cc: [email protected]
Subject: Re: [Templates] Single object list problem by VMethods

 

On 10/12/2009 10:52, [email protected] wrote:

 

> 4) Is there any way how this could be worked around?

 

Explicitly add the .list vmethod after your function/method call.  That
will

force the single item to a list while leaving an existing list
unchanged.  It

should resolve the ambiguity.

 

     [% your_function.list.sort %]

 

HTH

A

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to