i hate nvelocity's lack of docs

posted 11/15/2007 16:01:52 by matt flesch-kincaid: 32, grade level: 10 commentscomments(0) linklink
so after 30 minutes or so of beating my head against the wall i finally found that in nvelocity code like:
Hashtable hash = new Hashtable();
hash["foo"] = "bar";
// later
Console.Writeline(hash["foo"]);
becomes the easy part in the Controller:
Hashtable hash = new Hashtable();
hash["foo"] = "bar";
PropertyBag["hash"] = hash;
and the undocumented random black magic in the view:
$hash.get_Item("foo")
what doesn't work however is:
$hash["foo"]
$hash("foo")
$hash.item["foo"]
$hash.item("foo")
$hash.this["foo"]
$hash.this("foo")
${hash}["foo"]
${hash}("foo") 
etc....
no where is this listed in the velocity vtl documentation (brokenly linked from the nvelocity site). everything points the fact that $hash.item() would try to run hash.item(), hash.getitem(), hash.getItem() but no where does it proclaim this black magic to be needed. then i finally stumble upon getting the contents of the property bag from the monorail site showing the proper syntax after finally getting the google magic terms of "nvelocity idictionary notation" correct.

and of course searching for "nvelocity .get_Item(" yields tons of useful pages including "i'm trying to access an indexer on a nvelocity template with no success".... really?!?! an indexer?!?! is that what the kids are calling it these days? here's a tip for syntax faq entries.... use every possibly example of wrong syntax you can think of when documenting the right syntax. hashtable, idictionary, dictionary, dictionary entry, item, any of those words could have found me that damn page a lot sooner. hopefully this post finds it's way into someone's google results and makes them only waste 5 minutes.

update: more .net and nvelocity type posts can be found on my new tech blog

comments:

new comments are disabled...
re: i hate nvelocity's lack of docs
posted by: on 05/14/2008 16:32:18
Isnt it just $hash.foo? Just like objects.
re: re: i hate nvelocity's lack of docs
posted by: matt on 2008-06-20 02:51:46
Not if you want to iterate through or use a variable to access the item.