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
atom feed
comments(0)
link
nvelocity