What about using XML instead of a hash of hashes to represent your tree? Then you could use XPath expressions to do node references and even some calculations. Just a thought...
Buddy Burden wrote: > Andy/all, > > > $context->process(\$text); > > That was easy enough; thanx. > > Now for a harder (perhaps impossible) one ... > > Is there any way for TT2 to know the "path" of a given > variable? IOW, could I write a custom vmethod such that, say: > > [% Thing.OtherThing.subthing.pathname() %] > > would print "Thing.OtherThing.subthing"? Or is that just not doable? > > My ultimate goal--and maybe I'm just approaching it all > wrong--is have TT2 act a little bit like a spreadsheet. So, I > could have my objects contain "formulae" that are TT2 code, such as: > > Object.thing + 2 > > Easy enough, especially with the trick Andy just showed me. > But I also want to be able to refer to the "nodes" in my > tree (i.e. the hash of hashes that I'm passing into TT2) by > "relative paths". IOW, given a structure like this: > > ShoppingCart > |__________Item1 > |_____price = 100 > |_____qty = 3 > |_____ext_price = "ShoppingCart.Item1.price > * ShoppingCart.Item1.qty" > > I really don't want to have to refer to price and qty with > "absolute paths" like that. I'd much prefer something like: > > ext_price = "..price * ..qty" > > or whatever syntax I eventually settle on. But the point is, > turning "..price" into "ShoppingCart.Item1.price" is > trivial *if* I happen to know that I'm currently "on" > ShoppingCart.Item1.ext_price. > > Does any of that make sense? is there a whole better way that > I'm just not seeing? > > > -- Buddy > > _______________________________________________ > templates mailing list > [email protected] > http://lists.template-toolkit.org/mailman/listinfo/templates > _______________________________________________ templates mailing list [email protected] http://lists.template-toolkit.org/mailman/listinfo/templates
