We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26262
    • 18 Posts
    Recently i downloaded the new modx version (modx-2.0.5-pl-advanced.zip and modx-2.0.6-pl-advanced.zip) to start another client project and both are not working with the includeTemplate snippet.

    I’m ABSOLUTELY and COMPLETELY sure that all parameters, databases and code are EXACTLY the same. Completely identical in both projects but the snippet is not working. If i install the version 2.0.4 (modx-2.0.4-pl-advanced.zip) and try to use the snippet, it works.

    The snippet code is:
    <?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 .'SOURCE-TEMPLATE'.$tpl;
    ob_start();
    include($tpl);
    return ob_get_clean();
    


    Anyone knows why?
      Saulo
      • 3749
      • 24,544 Posts
      A few thoughts.

      If the snippet has default properties, $tpl will always be set, so empty($tpl) might be a safer test. And I assume you’ve tested with file_get_contents($tpl) to make sure something is being retrieved, made sure $base_path is correct, and made sure the case of the full filename is correct.

      ob_get_clean() doesn’t work on all platforms.

      This would be safer:

      $output = ob_get_contents();
      ob_end_clean();
      return $output;
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 26262
        • 18 Posts
        Hi...

        Of course, if template path is always set for different css files, ($tpl) should be set in the "Template snippet" separately and not in the "includeTemplate" snippet...
        Any of the options didn’t worked, i tried all them and nothing... : (
        Also i’m absolutly sure about $base_path and filename...

        Thou before i get this retrieve page (see attached file) and now i receive a completely empty page...
        Any advise?
        Thanks!
          Saulo
          • 3749
          • 24,544 Posts
          No clue. Sorry. Maybe someone else has an idea.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 26262
            • 18 Posts
            Thank you anyway.
            I will use the modx-2.0.4 and then if I know a resolution just make an upgrade to modx version...

              Saulo
              • 11076
              • 159 Posts
              strangely enough i use the same snippet in my template on 2.0.6 and it works fine, maybe you’re missing a slash (/) somewhere or somewhat miss spelled or something.

              how do you call the snippet? where are the files actually located?
              more info would help.

              don’t get back to 2.0.4
              our purpose is go forward and not back
              :)
                Michael Shraibman( gOmp)  | Freelance Design & Development | wink  impossible is nothing...
                • 26262
                • 18 Posts
                Hi..

                Yes it is very strange indeed...

                I call the snippet like this:
                [[includeTemplate? &tpl=`en/main.html`]]​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​


                The snippet have this code (already tried like BobRay suggests):
                <?php
                if ( !isset($tpl) || $tpl== "" ) return "Missing Template file!";
                
                $tpl = $base_path .'data/templates/'.$tpl;
                ob_start();
                include($tpl);
                return ob_get_clean();


                The main directory named "data" is located in the root directory and I’m using last MAMP version.
                I have tried almost everything and really can not understand. Is really strange and as i do not have a lot of experience with MODx, i’m a little frustrated...
                Didn’t start the project yet because I have until February so I’m trying to solve this... If I can not solve this in some time I must stick with 2.0.4 version.

                ???
                  Saulo
                  • 3749
                  • 24,544 Posts
                  Is there some reason you don’t want to just put the templates in chunks and use $modx->getChunk() to retrieve them. That’s the normal method in MODx.

                  That way, there’s no path and no output buffer to worry about.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 26262
                    • 18 Posts
                    Simply because i want to use an external HTML/CSS editor, without the need to login into MODx manager every time i need to edit the layout... and want personalized paths to source files...
                    This project will have at least three different layouts for different sections and the way I work it would be better for me.

                    Already tried to reinstall the MODx and MAMP...

                    And as I said before if I try it with version 2.0.4, IT WORKS!!! I have tried it again RIGHT NOW and is working. I have versions 2.0.4, 2.0.5 and 2.0.6 downloaded. This issue only happens with versions 2.0.5 and 2.0.6...

                    ??
                      Saulo
                      • 26262
                      • 18 Posts
                      NOW I REALLY DO NOT UNDERSTAND, REALLY!

                      I reinstall MAMP and MODx AAGGGGAAAAIIIINNNNNN and i suddenly start working. I REALLY do not know why!!!!!!! I’m felling so stupid thou I hope you guys believe me...

                      All I did was the same, EXACTLY the same I did before!!! With the exception that in this last try I installed the CodeMirror plugin, COULD THAT BE THE SOLUTION???(I don’t think so because it would be even more strange)

                      Anyway, I’m really happy laugh

                      Thank You all!!! RRREEAAAALLLLYYYY!
                        Saulo