I have searched and just can't seem to find this answer. How, within a snippet, do I get a specific template variable by supplying a resource ID number?
-
☆ A M B ☆
- 24,524 Posts
I was unaware of either solution provided. Thank youboth. I can definitely put both options to use.
You can also get it from the TV object:
$tvId = 12; // ID of the TV
$tv = $modx->getObject('modTemplateVar', $tvId);
or (a little slower)
$tv= $modx->getObject('modTemplateVar', array('name' => 'TvName'));
Then:
$resourceId = 12; // ID of the resource you want the value for
/* Get the raw value of the TV (faster, if you can use it) */
$value = $tv->getValue($resourceId);
/* Get the rendered value of the TV */
$value = $tv->renderOutput($resourceId);
BTW, this is all in my book, along with a couple other things.
http://www.amazon.com/gp/product/0983619409/ref=as_li_tf_tl?ie=UTF8&tag=m086d-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=0983619409