We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15001
    • 697 Posts
    Hi,

    Several hours now that I’m trying to call a TV or a snippet from within a TV.
    I cannot figure out how to do what I call "dynamic file binding".

    The idea is to store the content of my documents in external files.

    I can retrieve the content of a file from within a TV, by setting its value to @FILE assets/site/2.html
    for instance.

    Now, I’m trying to do this dynamically @FILE assets/site/[*id*].html
    and this does not work as I get this error : Could not retrieve document ’assets/site/2.html’. undecided

    I also tried making my variable call a snippet to generate the path. With no more success.
    Lastly, I observed that the "@FILE" is printed and does not bind anything if it is written directly in the content source code rather than in a TV.

    I already asked the French forum but could not find any solution to this problem yet.

    Thanks to any code guru for help !
      • 4172
      • 5,888 Posts
      perhaps works that?

      @eval return ’@FILE assets/site/’.$docid.’.html’;
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 3749
        • 24,544 Posts
        Or a snippet with just:

        <?php
        return file_get_contents($modx->config['base_path'] . 'assets/site/[*id*].html');
        ?>


          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
          • 15001
          • 697 Posts
          @Bob: You posted you answer while I was typing. So, what’s below might be outdated since I did not try your code. I’ll try it.

          @Bruno. Thanks. Unfortunately no; I got a parse error when running your code.
          I tried several TV / snippet combinations and got parse errors for all of them, including this one:

          The TV value:
          @EVAL modx->runSnippet("GetHtmlFileMatchingId")

          The snippet:
          <?php
          $docid=$modx->documentIdentifier;
          $fichier = '@FILE assets/site/'.$docid.'.html';
          return $fichier;
          ?>


          There is here a fantastic plugin by heliotrope to use a template stored in a remote file :
          http://modxcms.com/forums/index.php/topic,31819.msg197423.html#msg197423
          It works really fine.

          I’ll look at its code and try to make something similar for to inject documents from html files.
            • 4172
            • 5,888 Posts
            I think [*id*] is not parsed in the snippet, or is??
            <?php
            $docid=$modx->documentIdentifier;
            return file_get_contents($modx->config['base_path'] . 'assets/site/'.$docid.'.html');
            ?>
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 3749
              • 24,544 Posts
              @Bruno17: I believe you’re right. It’s parsed in returned output from the snippet, but not within the snippet itself, so your correction to my code would be required.
                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
                • 15001
                • 697 Posts
                Yes Bruno17’s snippet works fine.

                There is some plugin here to load a model from a file.
                http://modxcms.com/forums/index.php/topic,31819.msg197423.html#msg197423
                This plugin works fine and boosts productivity.

                I’m now tring to modify this plugin to make loading external documents also possible.
                The new code is here, but unfortunately does not work yet :
                http://modxcms.com/forums/index.php/topic,31819.msg197843.html#msg197843