We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11927
    • 105 Posts
    I think I can do this in Evo, but now I’m trying to move to Revo.

    So all I’m trying to do is get a resource by the id, process the tags, change the < and > to html entities &lt; and &gt;, and then output the HTML to the screen. I just want to see the source code of any page, just like when you right-click and go to ’View Source.’

    Below is my code for Revo. (which I know is wrong, because all I see on the screen is the number 6)
    <?php
    // [[Get_HTML? &id=`2`]]
    $holder = $modx->getObject('modResource', array('id' => $id) );
    
    $content = $modx->parser->processElementTags('', $holder->get('content') );
    
    $find = array('<', '>');
    $replace = array('<', '>');
    
    $content = str_replace($find, $replace, $content);
    
    return $content;
    ?>
    


    The Revo API is really hard to understand. I think what would help is examples, like the Evo wiki/API has.
      You may or may not want to use the code I write. It&#39;s probably all against the syntax rules of php and MODx. smiley

      Carpet Cleaning
      • 3749
      • 24,544 Posts

      There’s no easy way (that I know of) of getting the content field with all tags processed.

      Try this, though:

      <?php
      // [[Get_HTML? &id=`2`]]
      $holder = $modx->getObject('modResource', array('id' => $id) );
      
      $content = $holder->process();
      
      $find = array('<', '>');
      $replace = array('<', '>');
      
      $content = str_replace($find, $replace, $content);
      
      return $content;
      ?>
      

        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
        • 11927
        • 105 Posts
        No go. This is pretty much what I want to do, but unfortunately this only works in Evo (and doesn’t get the template code, but I could get over that).

        <?php
        // [[Get_HTML? &id=`1`]]
        $content = '';
        
        $holder = $modx->getDocumentObject('id', $id );
        
        $content = $modx->parseDocumentSource( $holder['content'] ) ;
        
        // the third argument is a literal newline (I just hit enter/return)
        $find = array('<', '>', '
        ', '	');
        $replace = array('<', '>', '<br />', '     ');
        
        $content = str_replace($find, $replace, $content);
        
        return $content;
        ?>
        



        The only line of code I can’t find a Revo equivalent for is this:

        <?php
        $content = $modx->parseDocumentSource( $holder['content'] ) ;
        ?>
        
          You may or may not want to use the code I write. It&#39;s probably all against the syntax rules of php and MODx. smiley

          Carpet Cleaning
          • 4172
          • 5,888 Posts
          you can try to load your content in a new chunk-object and process that chunk:

          <?php
          // [[Get_HTML? &id=`1`]]
          $content = '';
          
          $holder = $modx->getObject('modResource', array('id' => $id) );
          $chunk = $modx->newObject('modChunk');
          $chunk->setContent($holder->get('content'));
          $chunk->setCacheable(false);
          $content=$chunk->process();
          
          
          // the third argument is a literal newline (I just hit enter/return)
          $find = array('<', '>', '
          ', '	');
          $replace = array('<', '>', '<br />', '     ');
          
          $content = str_replace($find, $replace, $content);
          
          return $content;


          or try something like this:

          <?php
          // [[Get_HTML? &id=`1`]]
          $content = '';
          
          $holder = $modx->getObject('modResource', array('id' => $id) );
          $holder->set('cacheable',false);
          $holder->set('_processed',false);
          $holder->set('_content',false);
          $holder->set('template',0);//this was the line which changed something.
          //echo $holder->get('id');
          $content=$holder->process();
          
          
          // the third argument is a literal newline (I just hit enter/return)
          $find = array('<', '>', '
          ', '	');
          $replace = array('<', '>', '<br />', '     ');
          
          $content = str_replace($find, $replace, $content);
          
          return $content;


          or try file_get_contents

          <?php
          // [[Get_HTML? &id=`1`]]
          $content = '';
          /*
          $holder = $modx->getObject('modResource', array('id' => $id) );
          
          $chunk = $modx->newObject('modChunk');
          $chunk->setContent($holder->get('content'));
          $chunk->setCacheable(false);
          $content=$chunk->process();
          */
          /*
          $holder = $modx->getObject('modResource', array('id' => $id) );
          $holder->set('template',0);//this was the line which changed something.
          //echo $holder->get('id');
          $content=$holder->process();
          */
          
          $content = file_get_contents($modx->makeUrl($id,null,null,'full'));
          
          // the third argument is a literal newline (I just hit enter/return)
          $find = array('<', '>', '
          ', '	');
          $replace = array('<', '>', '<br />', '     ');
          
          $content = str_replace($find, $replace, $content);
          
          return $content;
          
          
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 3749
            • 24,544 Posts
            Bruno17 -- Putting the content in a chunk and then processing that is a brilliant idea. cool
              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
              • 11927
              • 105 Posts
              Thank you for helping with this, I really do appreciate it. I’ll test this out later and let you know what worked.

              Is there a place that I could learn more about how to understand the classes, methods, variables, etc. for modX Revo and how to use them? Maybe I need to go to the basics of classes, methods, etc without worrying about how they work in modX, but just how they work. But I’m not sure what to search for in order to find a website that would explain the basics to me. I can’t seem to understand or be able to translate the modX API to dumb people language (the language I understand best).
                You may or may not want to use the code I write. It&#39;s probably all against the syntax rules of php and MODx. smiley

                Carpet Cleaning
                • 11927
                • 105 Posts
                Thank you so much. Bruno17, the first two worked. I didn’t try the last one because I know that works if I wanted to get the html code of the template too.

                With both of your help, I’m starting to understand the Revo!
                  You may or may not want to use the code I write. It&#39;s probably all against the syntax rules of php and MODx. smiley

                  Carpet Cleaning
                  • 37242 ☆ A M B ☆
                  • 339 Posts
                  Thank you! That was the solution I was looking for!
                    • 3749
                    • 24,544 Posts
                    Quote from: heavensbest at Nov 11, 2010, 09:32 AM

                    Is there a place that I could learn more about how to understand the classes, methods, variables, etc. for modX Revo and how to use them?

                    This may help: http://bobsguides.com/revolution-objects.html. smiley
                      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