We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35592
    • 2 Posts
    I was following the screencast of http://designfromwithin.com/ in how to include the template html code dynamically, and i use the following snippet:

    <?php
    # 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();
    ?>


    The problem is that after saving the snippet, it removes the ( ?> ) from the php end tag.

    I’m using MODX Revolution 2.1.0-pl (traditional), installed in mamp running on osx.

    Can anyone help me please?

    Thanks in advance
      • 8924
      • 10 Posts
      The snippet actually looses the final closing tag of the php code, but it works perfectly. I am using it on revo 2.11.pl
      regards

      Enumaelis
        • 33968
        • 863 Posts
        Yes it’s like that by design - not sure of the exact reason but you don’t need the closing tag for snippets in the manager.
          • 42804
          • 5 Posts
          Hi everyone. I have to state that I am very very new to modx but I am exciting to dig in. I to have followed the "designfromwithin" tutorial and when I setup my snippet to call my index.html file, I get nothing but a blank screen. It seems to only work if I move the index.html (and related snippet/theme code) to the modx root. I don't get the "Missing Template File" message, just a blank screen. Any ideas?

          Snippet Info:
          <?php
          # Snippet to include template files from file system
          # USAGE: [[includeTemplate? &tpl='assets/templates/mytemplate/index.html']]

          if ( !isset($tpl) || $tpl=="" ) return "Missing Template file!";

          $tpl = $base_path.$tpl;

          ob_start();
          include($tpl);
          $output = ob_get_contents();
          ob_end_clean();
          return $output;


          Theme Info:
          [[includeTemplate? &tpl='assets/templates/mytemplate/index.html']]


          I can track it through the Snippet code, but like I said, never finds the index.html and displays it unless I just put everything in the root. I tried checking permissions, but I'm missing something.

          Any help you can provide would be greatly appreciated. Thanks.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Which version of MODx are you using?
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 42804
              • 5 Posts
              Revolution 2.2.6-pl (traditional) Quote from: sottwell at Feb 12, 2013, 01:03 PM
              Which version of MODx are you using?
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Don't use that. Use a static element for the template instead. http://rtfm.modx.com/display/revolution20/Upgrading+to+2.2.x#Upgradingto2.2.x-StaticElements
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 42804
                  • 5 Posts
                  Thanks for the quick response. Does that mean that there are some problems with paths in Modx?

                  Unless I'm misunderstanding, isn't that the equivalent of putting HTML directly into the theme and not using a snippet to call it dynamically?



                  Quote from: sottwell at Feb 12, 2013, 01:22 PM
                  Don't use that. Use a static element for the template instead. http://rtfm.modx.com/display/revolution20/Upgrading+to+2.2.x#Upgradingto2.2.x-StaticElements
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Not at all. A static element is a path to a file. The file's content is displayed; you can edit it either from the Manager or from the file. You can even use a Media Source if you want to. I used static templates in the MODXpo workshop last November in Utrecht.

                    Not that there is a problem with paths other than getting them right; the point is why run an unnecessary snippet when MODx provides the feature natively?
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org