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

    in a snippet I need the value of a TV of the same document. The name of the TV is ’NumberOfQuestions’. The input type of the TV is ’number’. I tried some versions i.E.:

    $Number = $modx->getTemplateVarOutput('NumberOfQuestions');


    or
    $Number = $modx->getTemplateVarOutput('NumberOfQuestions',"",$modx->documentIdentifier);


    The first one gives back an array, the second one just nothing.

    Can anybody give me a hint? Thanks!
      • 3749
      • 24,544 Posts
      Quote from: hgw at Jan 15, 2010, 01:44 PM

      Hello,

      in a snippet I need the value of a TV of the same document. The name of the TV is ’NumberOfQuestions’. The input type of the TV is ’number’. I tried some versions i.E.:

      $Number = $modx->getTemplateVarOutput('NumberOfQuestions');



      It’s expecting an array for the first argument so it should be:

      $Number = $modx->getTemplateVarOutput(array('NumberOfQuestions'));


        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 14197
        • 35 Posts
        BobRay is right, I’d like to mention that the function call result is also an array:

        $r = $modx->getTemplateVarOutput(array(’NumberOfQuestions’,$modx->documentIdentifier);
        $Number = $r[’NumberOfQuestions’];

        There is another way to do this too:
        $r = $modx->getTemplateVar("NumberOfQuestions",’name’,$modx->documentIdentifier);
        $Number = $r[’value’];

        I’ve not dug into the core code yet, but guessing from their names, getTemplateVarOuput might do some extra work by formatting those complicated TVs (e.g. image) from raw value to display so the second method might be slightly faster though it’s parameters are much more from obvious than the first one.


          • 12110
          • 122 Posts
          Thanks, it was a great help, if got it to work now.