We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1511
    • 144 Posts
    I created a TV with an EVAL expression but it seems that if I enter a line break in the textarea, the expression is not evaluated fully.

    Working example:
    @EVAL $a = 'a';$b = 'b'; return $a.$b;
    returns "ab".

    Not working example:
    @EVAL $a = 'a';
    $b = 'b'; 
    return $a.$b;

    This way the code can be used (if put in one single line) but is not readable any more. Is there any oter solution?
    Call of a function that returns the string I need? How do I include this code, as a snippet? How do I execute it for a TV?


    I want to have a drop down TV containing all the filenames in a certain folder and I guess this is te best way.
    TIA, AndraZ
      • 25663 MODX Staff
      • 12,272 Posts
      This will be rectified in the next release and is a known issue with 095. Sorry for the inconvenience.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 1511
        • 144 Posts
        No problem, I was just "curios". I can wait and in the meantime I’ll use it as a one-line function. smiley
          • 33372
          • 1,611 Posts
          You can also just put your @EVAL code in a snippet and run it from the TV like so:

          @EVAL return $modx->runSnippet(’yourSnippetName’);

          or like so if you need to pass variables to the snippet:

          @EVAL return $modx->runSnippet(’yourSnippetName’, array(’a’=>’a’,’b’=>’b’));

          I do this as a rule because it’s much easier to view and edit the @EVALed code as a snippet anyway.
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn't very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: ZAP at Jan 24, 2007, 10:53 AM

            You can also just put your @EVAL code in a snippet and run it from the TV like so:

            @EVAL return $modx->runSnippet(’yourSnippetName’);

            or like so if you need to pass variables to the snippet:

            @EVAL return $modx->runSnippet(’yourSnippetName’, array(’a’=>’a’,’b’=>’b’));

            I do this as a rule because it’s much easier to view and edit the @EVALed code as a snippet anyway.
            And though this does work, the fact that you are essentially eval()’ing within another eval() is not necessarily a good practice for performance or security reasons. However, soon enough, only the @EVAL will use the actual eval() function, and all will be well...
              • 1511
              • 144 Posts
              Thanks, that’s what I was looking for as a "best practice".