I want to access the first row of the entries in a child table for a content type.
I want the equivalent of this in a single line (by referring by index)
#foreach( $row in $sys.item.getNodes('allCustomers'))
$row.getProperty('rx:customerId').String
#break
#end
The following do not work:
$sys.item.getNodes('allCustomers').get(0)
$sys.item.getNodes('allCustomers')[0]
Please advise.
I do not believe this is directly possible as the Node.getNodes method that is under the covers returns a NodeIterator object, which is why velocity makes you go at it in a sequential-access fashion (see http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/NodeIterator.html). I assume you want to do this just to have cleaner-looking code, so if you find yourself needing random-access to child table nodes, you might want to create a custom macro that iterates through it, puts it into an array and returns it. Maybe something like this already exists in some of the PSOToolkit stuff.
Thanks for your reply. Since direct access via index is ruled out (yes, for the sake of cleaner code), I’ll stick with the iteration code and maybe look as psotoolkit sometime.
thanks.