We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38537
    • 34 Posts
    Hey there,

    I have a problem with my snippet.
    I want to check if a tv from the current template has a value or not.

    So, I read this topic:
    http://rtfm.modx.com/display/revolution20/Accessing+Template+Variable+Values+via+the+API

    There is the code to become the value of my tv:
    $page = $modx->getObject('modResource', 123);
    return $modx->getTVValue('bio');


    But when I use this snippet in my template I become the following error message:
    Fatal error: Call to undefined method modX::getTVValue() in /web/core/cache/includes/elements/modsnippet/8.include.cache.php on line 7


    Why that doesnt work?
    And how I can check if my tv has a value ort not?

    Hope you can help me.

    Kind regards,
    z.
      • 22427
      • 793 Posts
      $page = $modx->getObject('modResource', 123);
      return $modx->getTVValue('bio');
      should be
      $page = $modx->getObject('modResource', 123);
      return $page->getTVValue('bio');
      (to get the TV value of that page)

      Or try this:
      $page = $modx->getObject('modResource', 123);
      $id = $page->get('id');
      $tv = $modx->getObject('modTemplateVar',array('name'=>'bio'));
      $processedValue = $tv->renderOutput($id);