We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    The parser will always use the template from the resource’s template field.

    The only way I can think of would be to write a plugin that would change the template before the page is parsed. OnParseDocument and OnWebPagePrerender would be too late and OnHandleRequest (I think) would be too early. It might work with OnWebPageInit, however. Of course you’d have to figure out a way to tell the plugin when to act and which template to use.

    It would be easier just to have multiple versions of the resource using different templates.

    What is it you’re trying to do? Is it possible that you could do it with separate chunks and/or CSS? That’s *much* easier.
      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
      • 17016
      • 138 Posts
      Hi Bob,
      our goal is to build a Newsletter which we have to send in plain-text and html as multipart. For this we have to upload two files to our Newsletter-Tool. Therefore we have two templates which generate two documents (.html and .txt) out of one resource. Hope we can manage this somehow.

      Thanks a lot for your help!
      Letti
      • This is what SymLinks can do. Simply point it at another Resource and declare a different Template.
          • 17016
          • 138 Posts
          Thanks a lot!

          If I understand it correct it is possible to put the output of these two resources in a variable by a code like this:

          $mydocument = $modx->getObject('modResource', 100);
          $thehtmlpage = $mydocument->process();
          


          And the same for the Symlink-Resource. Is this correct or is there a better way to realize this?
          • No, that is not going to process anything that is non-cacheable and there are a number of other dependencies that might not produce the proper output this way. You should let MODX handle the requests and produce the output from a Resource. Otherwise, you’ll need to reproduce most of the entire request handling process to properly reproduce the same output the Resource would produce when called as intended through the MODX gateway.
              • 3749
              • 24,544 Posts
              I thought symlinks, like weblinks, used the template of the target page. huh

              If I’m wrong, there might still be time to change that part of the book. tongue
                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
              • At some point late in 2.0.x releases, the default behavior of Symlinks changed to override values in the target if not empty, respecting the template of the Symlink. You can configure this not to merge fields via System/Context Settings (see the symlink_merge_fields Setting), as well as specify specific fields to exclude from the merge anytime modX->sendForward() is used (see forward_merge_excludes System/Context Setting with default value of "type,published,class_key,context_key").