We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32381
    • 1 Posts
    Is it posible to use template files instead of making templates in resources-templates?

    it will be a lot easier to edit.

    ive tried to include a snippet that includes my template and that works but is there a way to do it without snippets?
    or any other tips

    thx, WIjbaL
      • 33337
      • 3,975 Posts
      AFAIK, I think snippets are the only way to include php scripts.
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 5123
        • 12 Posts
        I just wanted to ask if anything changed in this issue, that is what’s the best way to include a template from a file

        editing template in modx manager isnt so convenient and copy&paste method gets really tiresome

        thanks for the answer in advance and thanks for such a wonder which modx surely is - it’s awesome project smiley

        greets!
          • 8960
          • 150 Posts
          This is completely possible. Here’s how you do it...

          Create a Snippet called includeFile and copy-n-paste in this code:

          <?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;
          ?>


          Once you save that, make a new Template or edit your existing template. Erase any Template code you have in there and paste in this call to the includeFile Snippet you just created:

          [[includeFile? &file=`assets/templates/YourTemplateName/YourTemplateHTMLFile.html`]]


          I took this from the code I found in the Molio templates. It works perfectly for me. I hate having to always paste in my new HTML code after I edit it on my local machine.

          Cheers!
            • 5123
            • 12 Posts
            many thanks, works perfectly smiley
              • 29076
              • 615 Posts
              This looks great. A question: Do you then have an auto-transfer of your html-template-file? Or how do you do this? To make this efficient, i mean?
                I think, thererfor I am! But what I am, and why...?
                • 8960
                • 150 Posts
                Well, my workflow is this:

                1) Edit HTML in Dreamweaver on my local machine.
                2) Upload the HTML file(s) within Dreamweaver’s FTP function to the live site.

                I imagine a lot of web developers/designers work this way, so that’s why editing the HTML within MODx’s template page is such a pain. Even if you don’t have Dreamweaver, it’s just as easy to drag-n-drop the files over to the live site through any FTP client.

                Another way I work is actually even easier for me. I’m on a Mac and I use YummyFTP. With that FTP client, I can find the file on the live site that I want to edit, then click on the editor button and it downloads the file to my editor of choice (TextMate), I make my edits and when I hit save, YummyFTP automatically uploads the saved file back to my live site. I do this when I’m making small changes since I don’t use TextMate fulltime (yet).

                So you can see there’s lots of options for you to make this as efficient as possible.
                • I use the same technique with Textmate and Transmit er16004. I think you’ll reallly like what the future has in store. wink
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 32319
                    • 129 Posts
                    For anyone interested in other Mac software options...

                    Most of the major Mac FTP clients integrate with BBEdit using the same kind of direct integration as you mentioned with YummyFTP and TextMate.

                    This system works very efficiently for me.
                      "Regret for the things we did can be tempered by time; it is regret for the things we did not do that is inconsolable."
                      -- Sydney Harris
                      • 8960
                      • 150 Posts
                      "...And I’m a PC":

                      FileZilla for FTP: http://sourceforge.net/projects/filezilla
                      EditPadLite for editing text (better than Notepad): http://www.editpadlite.com/

                      Both of these are free and can do what we’re talking about on the Mac... but with less fun.