⚠️ Urgent! Active Attacks on MODX Revolution Sites Below Revolution 2.6.5
Subscribe: RSS
  • Aside from Bob's excellent article on Advanced Symlinks which I have referenced at the end of this post, does anyone have any experience of the "symlink_merge_fields & forward_merge_excludes" settings in MODX?

    Here's my question:

    With "symlink_merge_fields" set to "yes" and "forward_merge_excludes" set to "pagetitle,longtitle" or any other MODX field. The behaviour is exactly as expected, ie. all values are taken from the Symlink within the exception of pagetitle & long title which are excluded from the Symlink & get their values from the target resource. However this does not appear to work with Template Variables, so for example with "forward_merge_excludes" set to "pagetitle,longtitle,myTV", pagetitle & longtitle are excluded but myTV still gets it's value from the Symlink.

    Is this supposed to work with Template Variables? - Bob's article says, "yes" but it doesn't work for me...

    https://bobsguides.com/blog.html/2017/02/28/advanced-symlinks-i/

    • Is the TV empty on the Symlink page (and set to allow blank)? It has to be if you want the value from the target page.

      You may also have to make sure the TVs default value is blank.
        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
      • Thanks Bob,

        Actually I've just discovered it does work with template variables. My problem was that I was trying to call the TVs via a snippet, eg..

        $page = $modx->getObject('modResource', $resouceId);
        $myTV=$page->getTVValue('myTV');
        


        Of course when accessing $resourceId as a parameter it always uses the ID of the resource which contains the snippet. If it's a Document, then the Document ID. If it's a Symlink, then the Symlink ID. The symlink_merge_fields has no effect in this case.

        I'm current trying to figure out a workaround for this. Is there something obvious I'm missing here?
        • The logic of this is hurting my brain. wink

          I assume there's some reason you can't just leave the symlink page's TV values blank and use a tag where you want to display the target page TV value:

          [[*MyTv]]


          Does this return the ID of the Symlink, or the Target?

          return "ID: " . $this->modx->resource->get('id');


          If it's the target, this should work:

          return $this->modx->resource->getTVValue('MyTv');


          If it's the Symlink, this should work, though it's a little tortured:

          $symlink = $modx->getObject('modResource', $modx->resource->get('id'));
          
          if ($symlink) {
             $targetId = (int) $symlink->get('content');
          }
          
          $tv = $modx->getObject('modTemplateVar', array('name' => 'MyTv'));
          
          /* If you can use the raw value of the TV */
          return $tv->getValue($targetId);
          
          /* If not */
          return $tv->renderOutput($targetId);





            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