On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Thanks Bob,

    i get only the option site_url and not the uri of the page. What i'm do wrong?

    (its my tvId wrong? I dont know the id of uri..)

        $resourceId = $unterseiteid; //$modx->resource->get('id') ??
        $tvId = uri;
      
        $query = $modx->newQuery('modTemplateVarResource', array(
        'contentid' => $resourceId,
        'tmplvarid' => $tvId,
        ));
        $query->select('value');
        return $modx->getOption('site_url') . $modx->getValue($query->prepare());
    
    • That will happen if the $resourceId or the $tvId are wrong. TvId must be a number (the number in parentheses next to the TV's name in the Elements tree).

      The $resourceId, may also be wrong (try it with the correct TV ID first), but fixing it depends on where and how the snippet is called. Since I think it's in a Tpl chunk, this might work:


      [[!snippetName? &docId=`[[+id]]` ]]


      Then in the snippet:

      $resourceId = $modx->getOption('docId', $scriptProperties);


        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
      • Thank you for your support.

        Quote from: BobRay at Nov 30, 2017, 11:03 PM
        (the number in parentheses next to the TV's name in the Elements tree)

        In the Elements tree i see only my tvs but not the regular tvs like uri, pagetitle, longtitle... Where i can see the tv for example "pagetitle"?


        If i set my tv (2) für tvId, then i get the same result.

        But i change the snippet and it works now:

        $tv = "uri";
        $id = "713";
        $parent = $modx->getObject('modResource', $id);
        return $modx->getOption('site_url'). $parent->get($tv);
        
        [ed. note: joe-petts last edited this post 1 year, 8 months ago.]
        • Resourcefields and Templatevariables are two different things.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
          • Ah ok. I messed things up..