We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 436 ☆ A M B ☆
    • 265 Posts
    Quick question, which I think I already know the answer to...

    Is it possible to have some or all of the Resources and Documents on the server, mainly the Template Resources - I’d like to be able to use a text editing app such as Panic’s Coda and connect to the site via FTP and edit the Templates - then let the client login to the CMS and edit the documents and content.

    This is the beauty of other such CMSes like WordPress, where its so easy to go in and amend the templates... At the moment it is possible to have the CSS as a static file on the server or in the database, could I do this with any other file?
      MODX Ambassador for Thailand. Managing Director at Monogon, a web design and development studio based in Bangkok, Thailand. - Follow me on Twitter.
      • 30223
      • 1,010 Posts
      Yes that’s possible. The way to do this with templates is to
      1. create a snippet which includes the template on the file system (name it includeTemplate). In it’s simplest form something like this:
      <?php // don't copy this line
      # Snippet to include template files from file system
      # USAGE: [[includeTemplate? &tpl=`mytemplate/template.html`]]
      
      if ( !isset($tpl) || $tpl== "" ) return "Missing Template file!";
      
      $tpl = $base_path .'assets/templates/'.$tpl;
      ob_start();
      include($tpl);
      return ob_get_clean();
      


      2. Create your templates in the modx manager and only enter this as the content:
      [[includeTemplate? &tpl=`mytemplate/template.html`]]

      where &tpl points to the template saved underneath assets/templates/

        • 26903
        • 1,336 Posts
        Interesting, I’ve tried this in the past and didn’t get it to work. I had a page with an e-form snippet in the content area, when I included the template for this page as you have said above( I too wanted it to be external) it didn’t parse the e-form snippet, it just dumped it as a string in the content area. I thought this may be because of nested eval’s or something as the template itself is now being included via an eval, then again I may just have got it wrong somewhere.
          Use MODx, or the cat gets it!
          • 436 ☆ A M B ☆
          • 265 Posts
          ah thanks TobyL, I forgot to come back and check this topic, a local MODx friend, PixillionSaul actually showed me a similar snippet he’d been using:

          Snippet name:
          [[IncludeFile]]


          <?php
          # Snippet to include files from filesystem
          # [[includeFile? &file=`assets/templates/mytemplate/file.html`]]
          
          if ( !isset($file) || $file== "" ) return "No file specified."; //check if there's a file given.
          
          //Start the buffer
          ob_start();
          
          //include
          include $file;
          
          //get contents from the buffer
          $ob_contents = ob_get_contents();
          
          //and kill/delete the buffer
          ob_end_clean();
          
          //return it to MODx
          return $ob_contents;
          ?>


          and then you’d call it like this into one of your templates or something:
          [[IncludeFile? &file=`assets/templates/templates.about.htm`]]
            MODX Ambassador for Thailand. Managing Director at Monogon, a web design and development studio based in Bangkok, Thailand. - Follow me on Twitter.
            • 7231
            • 4,205 Posts
            Just a php question: I would most like have tried doing this with a simple include() but I noticed that both snippets use the output buffer. Would an include not work or be considered ’wrong’?
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]