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

    i’m using revolution and i’m trying to retreive a collection of documents (all children of parentID=3), loop through them and check for each is it has a specific TV.

    [tt] $c = $modx->newQuery(’modResource’);
    $c->where(array(
    ’modResource.parent’ => 3,
    ));

    $c->sortby(’menuindex’,’ASC’);
    $resources = $modx->getCollection(’modResource’,$c);

    foreach ($resources as $resource) {
    $tv = modx->getTemplateVar(’jobtitle’,’*’,$resource->get(’id’)) ;
    $output .= $tv;
    }[/tt]

    Now the modx->getTemplateVar does not seem to work. am i doing something wrong?

    Now i started looking for some documentation on it but the docs i could find seem to suggest getTemplateVar is depreciated. is that true?
    And is the class reference at http://api.modxcms.com/ valid for revolution? is it complete? (getCollection is not in there) or is there another link with revolution class reference.

    thanks

    Ralph
      • 3749
      • 24,544 Posts
      You could get the TV with

      $tvObj = $modx->getObject('modTemplateVar',array('name'=>'jobtitle')) ;


      and then use

      $tv = $tvObj->renderOutput($resource->get('id'));


      But since you already have the resource, you can use this easier method:

      $tv = $resource->getTVValue('jobtitle');
      // or
      $tv = $resource->getTVValue($id);  // Where $id is the ID of the TV (not the resource)
      $output .=  $tv;


      Note that it’s getTVValue(), not getTvValue().
        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
        • 24629
        • 370 Posts
        Hi Bob,

        Thank you, that worked. any idea if the api http://api.modxcms.com/ reference is complete? or why getCollection is not to be found there?
          • 3749
          • 24,544 Posts
          I don’t know if that is up-to-date or not. I couldn’t reach getCollection() from the tree at the left (that seems wrong, BTW), but it’s there in the guide.

          It’s an xPDO method (the $modx object extends the $xpdo object). Click on "The MODx Revolution Core" on the right side, then on "xPDO."
            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