We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2582
    • 4 Posts
    Is it possible to include a document within a template? I have created a template for the front page of the website, and one that is used throughout the interior of the site. On the front template I would like to include three other documents, much in the same way "chunks" function. The reason I would like to use templates, is because I can layout my information in a visual hierarchy which would be easier for the end users to understand the organization and layout fo the information on the website.
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: azdesign at Jan 27, 2007, 12:29 PM

      Is it possible to include a document within a template? I have created a template for the front page of the website, and one that is used throughout the interior of the site. On the front template I would like to include three other documents, much in the same way "chunks" function. The reason I would like to use templates, is because I can layout my information in a visual hierarchy which would be easier for the end users to understand the organization and layout fo the information on the website.
      Just write a snippet that includes the file. But why not just write pure php files and include them then? What does MODx offer you if you do not want to use the built in templating system?
        • 2582
        • 4 Posts
        Don’t get me wrong, I think the templating capabilities is what got me hooked onto this CMS, but if I can stay away from using chunks and instead use documents for the same use as chunks, that is what I’m trying to do. I would still be using templates, but would be integrating content from multiple documents (as opposed to chunks).

        It simply comes down to my desire to use the hierarchical view in the manager to organize my information on the site and allow the user to access and edit all of that content from that view.

        But I understand your point with the snippet, I’ll have to take a look into that... couldn’t be too difficult.

        Thanks
          • 22303 MODX Staff
          • 10,725 Posts
          I misunderstood a little about what you meant; and not at all difficult...I think just doing something like this in a snippet...
          if (isset ($file)) {
              $content= '';
              ob_start();
              if (@include ($modx->config['base_path'] . $file)) {
                  $content= ob_get_content();
              }
              ob_end_clean();
          }
          return $content;

          and calling it like
          [!FileInclude? &file=`foo/bar.html`!]

          will do the trick...
            • 2582
            • 4 Posts
            Close, but Instead of including a document in the template, I want to just include the document from the database. Though, I’m sure that snippet would come handy one way or another, similar premise but that would mean one must use the file manager to make changes to such a file.
              • 7923
              • 4,213 Posts
              Use the getField snippet in the template


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."