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

    $allowedTvNames = array('tv1','tv2');
    $templateVars =& $resource->getMany('TemplateVars',array('name:IN' => $allowedTvNames));


    is this correct ?

    I don’t get any results when I applied the criteria array(’name:IN’ => $allowedTvNames)
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Any reason you’re assigning it as a reference (=&)?

      The return value of the getMany method is an array of objects, so you don’t need the reference.


      Also, are your TVs actually named "tv1" or "tv2"?
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 22303 MODX Staff
        • 10,725 Posts
        Getting Template Variables from a Resource is a special relationship that has custom criteria defined. At the moment, if you pass criteria to getMany() for TemplateVars, this criteria will override the custom criteria that is being added automatically when getMany(’TemplateVars’) is called without criteria. In this case, you might be better off getting the collection of modTemplateVar objects and then getting the value/output for your Resource from each.

        <?php
        $allowedTvNames = array('tv1','tv2');
        $templateVars = $modx->getCollection('modTemplateVar', array('name:IN' => $allowedTvNames));
        foreach ($templateVars as $tv) {
            echo $tv->get('name') . " = " . $tv->renderOutput($resource->get('id')) . "\n";
        }
        
          • 4619
          • 23 Posts
          Thanks Jason.
          You are right, it’s better (faster) to start from the names of allowed tvs to get the values rather to find and filter the Tvs of the resource.

          Otherwise $templateVars =& $resource->getMany(’TemplateVars’); works only if your resource has a template field.
          This was the reason why in mys case this didn’t work before.