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

    I’m wondering what i can use to replace this call:

    $modx->getTemplateVarOutput


    that was in Evolution but doesn’t seem to be in Revolution, how would i go about using it to get a document’s content?

    I’ve been using it like this:

    $content = $modx->getTemplateVarOutput('content', '23');


    and it returns the content of document with an id of 23.
      • 1778
      • 659 Posts
      try this
      $resource= $modx->resource;
      $content=$resource->get('content');
      


      Enjoy
        • 21884
        • 57 Posts
        thanks!

        i tried:

        $pageID = "14";
        $resource= $modx->$pageID;

        but that returns NULL

        not sure how to specify which modx resource i’m calling?
          • 1778
          • 659 Posts
          If you want to access a document with ID 12 for example try
          $resource = $modx->getObject('modResource',12); // retreive doc with ID12
          $content = $resource->get('content'); // access the content of resource with ID12 
          


          Cheers
            • 21884
            • 57 Posts
            ok so that didn’t work, i got it working like this instead:

            $content=$modx->getObject(’modResource’,array(’alias’ => $pageAlias));
            echo $content->get(’content’);

            i think modx should have a simpler way of getting ahold of a resource by the id and returning the content of that resource, i’m not sure i understand why ID is not in the available list of fields for modResource
              • 1778
              • 659 Posts
              This code works fine for me

              <?php
              $resource= $modx->getObject('modResource',3);
              
              $mycontent = $resource->get('content');
              
              echo $mycontent;
              ?>
              


              If you want to use your

              $pageID = "14";
              $resource= $modx->$pageID;
              


              You should do this
              $pageID = 14; // no quotes here ID is an integer
              $resource = $modx->getObject('modResource',$pageID); // retrieve the modResource with your ID
              echo ($resource->get('content')); // retrieve and echo the field content in the resource
              

              hope this helps

              I can’t find a easier way to achieve this
                • 3749
                • 24,544 Posts
                Getting the raw or processed value of TVs is trickier, because their values are not stored in the same table as the document fields.

                See the TV section here: http://bobsguides.com/revolution-objects.html
                  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
                  • 21884
                  • 57 Posts
                  that worked nicely, thanks!
                    • 30023
                    • 172 Posts
                    Hi,

                    I am trying to translate the following from the evo API to the revo API:

                    $modx->getTemplateVarOutput('*', $docid, 1)


                    I’ve found out how to get specific tvs using getObject and getContent, but not how to get all the tvs (including those from modx_site_content as well as the custom tvs).

                    -- Tim.
                      • 3749
                      • 24,544 Posts
                      If you want an array of the TV objects themselves (rather than the TV values associate with individual resources), you could use

                      $modx->getCollection('modTemplateVar');


                      If you need the raw or processed value of the TVs associated with specific resources, you can get the resources first and then loop through them and get their TVs with getMany. Something like this:

                      $resources = $modx->getCollection('modResource');
                      
                      foreach $resources as $resource {
                          $id = $resource->get('id');
                         $tvs = $resource->getMany('TemplateVars');
                          foreach ($tvs as $tv) {
                              $rawValue = $tv->getValue($id);
                              $processedValue = $tv->renderOutput($id);
                          }
                      }


                      There’s probably a way to get the resources and their TVs in one call with getCollectionGraph(), but I’m not sure what the second argument would be or how to extract the TV values.
                        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