We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42562
    • 1,145 Posts
    So you read this
    and this
    and even this
    And you are still scratching your head?
    Yea, me too... I scratched my beard bald!

    1. I have a plugin that must fire only if a resource has a template to which is attached a particular TV
    2. This resource will have its own value in the TV, filled or empty
    3. This TV must have a default_value
    4. I have the TV name and resource ID that's all

    A Perfectly Working Example
    if ($modxEventName == 'OnDocFormPrerender') {
      $tvName = $modx->getObject('modTemplateVar', array('name' =>'tvNAME')); // you could wrap this with an IF before you continue
      $tvId = $tvName->get('id');
      $tvValue   = $resource->getTVValue($tvId);
      $tvTemplateId = $modx->getObject('modTemplateVarTemplate', array("tmplvarid" => $tvId))->get("templateid");
      $resourceTemplateId = $resource->get("template");
      if ($tvValue  || $tvValue == ''){
        if ($tvTemplateId == $resourceTemplateId) {
              //do stuff

    what's in a name? [ed. note: donshakespeare last edited this post 8 years, 3 months ago.]
      TinymceWrapper: Complete back/frontend content solution.
      Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
      5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
      • 4172
      • 5,888 Posts
      one joined query, could also work, something like that(untested):

      $tvname = 'TVname';
      $c = $modx->newQuery('modTemplateVar');
      $c->select($c->xpdo->getSelectColumns('modTemplateVar','modTemplateVar', ''));
      $c->select($c->xpdo->getSelectColumns('modTemplateVarResource','TemplateVarResources', 'tvvalue_'));
      if ($tv = $modx->getObject('modTemplateVar',$c)){
          $value = $tv->get('tvvalue_value');
          $default = $tv->get('default_text');
          //do stuff

        you can buy me a beer, if you like MIGX