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

    I just started a new project on revolution and I could not find a solution to keep the templates in files.

    So, I made my own based on the includeTemplate for Evo. Is there a better way to do this in Revolution?

    Here’s the code:

    <?php
    
    /*
    Snippet to include template files from file system. Put your templates in assets/templates
    USAGE: [[incTpl? &path=`home.html`]]
    */
    
    if ( !isset($path) || $path== "" ) 
    	return "Missing Template file!";
    
    $path = MODX_BASE_PATH . 'assets/templates/' . $path;
    
    ob_start();
    include($path);
    return ob_get_clean();
    
    ?>
      • 28215
      • 4,149 Posts
      Yes:
      <?php
      /*
      Snippet to include template files from file system. Put your templates in assets/templates
      USAGE: [[!incTpl? &path=`home.html`]]
      */
      $path = $modx->getOption('path',$scriptProperties,'');
      if (empty($path)) return 'Missing Template file!';
      
      $path = $modx->getOption('assets_path',null,MODX_ASSETS_PATH.'templates/').$path;
      
      $o = file_get_contents($path);
      return $o;
      ?>
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 5340
        • 1,624 Posts
        Thx,

        I have to start learning those API’s

        Also ’assets_path’ should be just ’path’
          • 28215
          • 4,149 Posts
          tbh, your script should just be this:

          <?php
          $path = $modx->getOption('path',$scriptProperties,'');
          $o = '';
          if (!empty($path)) {
              $o = file_get_contents($path);
          }
          return $o;
          ?>
          


          And called like this:

          [[!incTpl? &path=`[[++assets_path]]templates/home.html`]]
          
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 5340
            • 1,624 Posts
            Thx


            I modified your code to

            $path = MODX_ASSETS_PATH . $modx->getOption('path',$scriptProperties,'');
            $o = '';
            if (!empty($path)) {
                $o = file_get_contents($path);
            }
            return $o;


            [[!incTpl? &path=`templates/home.html`]]