NVelocity and Collections (and Possibly Arrays)

I just spent 40 minutes banging my head against a pointy sharp wall. I’m using NVelocity as my view engine on a Monorail project and couldn’t figure out how to access an element of a collection.

$collection[0]          // Doesn't work
$collection(0)          // Nuh-uh
$collection.[0]         // Nope
$collection.get(0)      // As per Velocity Docs.  Nope
$collection.get_Item(0) // THIS WORKS!

Ok, so that’s incredibly not obvious. I couldn’t find any reference to it on the Castle Project Website, the Velocity docs the Castle site refers you to, or pretty much anywhere.  I did find it in the google group though, but only after a lot lot lot of searching. So hopefully this will save someone out there a few minutes of their life.

Or maybe I should just switch to Brail.

This entry was posted in Development. Bookmark the permalink.

5 Responses to NVelocity and Collections (and Possibly Arrays)

  1. Shey says:

    $collection.get_Item(0)!!!!!!

    sorta reminds me of C++ STL vectors

  2. Gauthier Segay says:

    This is due to :
    - lack of syntax in nvelocity
    - class instance’s indexer being compiled as Item CLR property
    - Instance properties being compiled as get_PropertyName and set_PropertyName CLR methods

  3. Pingback: Prozac dosages.

  4. TD says:

    Hi James, you just saved this person at least an hour of research. Thanks!

  5. @TD:

    Glad it helped someone!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>