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

    I run into an issue in Revo 2.0.8 with @EVAL binding for a TV.

    A simple TV named [tt]TV1[/tt] of type Radio Options and [tt]option1||option2||option3[/tt] as Input Options Values works like expected: The radio buttons with their labels show up.

    Another one, [tt]TV2[/tt] of type Radio Options but with
    @EVAL return $modx->runSnippet('getOptions');

    as Input Options Values does not. Here the snippet [tt]getOptions[/tt] is the following:
    <?php
    return 'option1||option2||option3';
    ?>

    Instead of the buttons for all the options a single radio button shows up without caption.

    Any hint what I’m doing wrong is highly appreciated.

    ottogal

      • 8609
      • 607 Posts
      I’m able to get this to work fine with some minor modifications to the snippet, though I don’t think that’s your issue. Here’s my code. For the getOptions snippet I have

      <?php
      return "option1==option 1||option2==option 2||option3==option 3";
      


      And then I place this in the Input Options Value:

      @EVAL return $modx->runSnippet('getOptions');
      


      Make sure you’re putting this in the Input Options Value box and not in the Default Values one, I make that mistake sometimes smiley
        • 22427
        • 793 Posts
        Thank you for your thoughts, einsteinsboi.

        The use of [tt] option1==option 1||option2==option 2||option3==option 3 [/tt] instead of [tt]option1||option2||option3[/tt] doesn’t change the result (in fact, I had it like that before and just abreviated it for the post).
        Quote from: einsteinsboi at May 31, 2011, 12:02 AM

        Make sure you’re putting this in the Input Options Value box and not in the Default Values one, I make that mistake sometimes smiley
        Yes, I once made this mistake too, but it’s in the Input Options Value box, indeed.
          • 8609
          • 607 Posts
          hmm, is this a live site? If yes and you need a second set of eyes I’d be happy to take a look because it works on my setup just fine. You can create a temp login for me and send the details via PM
            • 22427
            • 793 Posts
            That’s very friendly of you, but it’s just local on my hard disc.

            But I saw that the too far simplified version of my snippet works fine indeed, so I give you a less simplified one.
            The point is that the options for the [tt]TV2[/tt] are the subfolders of a folder, and the snippet [tt]getOptions[/tt] has to retrieve these subfolders and put them into the ||-separated list for the Input Option Values of the [tt]TV2[/tt] .
            Here is the snippet code:
            <?php
            $folder = 'path/to/my/folder';
            $output = '';
            $files = array();
            $handle = opendir($folder);
            while( $file = readdir($handle) ) {
            if ($file == "." || $file == "..")
            continue;
            else {
            $files[] = $file;
            $output .= '||'.$file.'==/'.$folder.'/'.$file;
            }
            }
            closedir($handle);
            $output = substr($output,2); // remove leading ||
            return $output;
            ?>

            If I put the call [tt][[!getOptions]][/tt] directly into the content of the page it results in the correct string of options...
              • 3749
              • 24,544 Posts
              I think you have an extraneous || at the beginning of your return value.

              Make that:

              $files[] = $file.'==/'.$folder.'/'.$file;


              Then move the $output line outside the loop, and make it:

              $output = implode('||', $files);


              You might want to test it in a snippet first to make sure the output is correct.

                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
                • 22427
                • 793 Posts
                I think you have an extraneous || at the beginning of your return value.
                No, I remove it before the output:
                $output = substr($output,2); // remove leading ||
                As I said, my snippet delivers the correct string when I call it directly.
                  • 3749
                  • 24,544 Posts
                  Sorry, I missed that.

                  I don’t see anything wrong unless the slashes are causing trouble (and they shouldn’t). Are you getting any output at all?
                    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
                    • 22427
                    • 793 Posts
                    Thanks to hints from the German community I found the solution: In my snippet the line
                    $handle = opendir($folder);
                    has to be changed to
                    $handle = opendir(MODX_BASE_PATH.$folder);

                    I’m glad to have got it solved - but I don’t really understand the necessity of this modification, given that the snippet call [tt][[!getOptions]][/tt] even before put out the correct string... huh

                    Thank you all for your glance at my stuff!
                    ottogal
                      • 3749
                      • 24,544 Posts
                      I think it’s because the snippet is in the front end and operates at the root of the site. In the Manager, you’re in the /manager directory, so the TV was looking there.
                        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