We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5950
    • 44 Posts
    I’m trying to use the ’fileexists’ modifier documented on the wiki:
    http://wiki.modxcms.com/index.php/PHx/CustomModifiers


    Here’s my snippet ("phx:fileExists"):

    <?php
    condition[] = intval(file_exists($output));
    ?>



    Here’s my call:

    [+phx:if=`{{dsURL}}` :fileExists:then=`{{DS_link}}` :else=``+]


    If I remove the space from between ` and : then I get a syntax error (unexpected ")") on any page featuring this call.

    If I add the spaces, the syntax error goes away, but the snippet (phx:fileExists) doesn’t actually do anything. The page just displays:

    [the url built in chunk "dsURL"]` :fileExists:then=`[the code from chunk DS_link]` :else=`

    No beginning `, no trailing `

    I have no idea what I’m doing wrong. I’m not used to troubleshooting PHx, it usually works on the first go!

    Using PHx 2.1.3 and MODx 1.0.2


    Any help is appreciated!
      • 5950
      • 44 Posts
      Has anyone ever played around with this modifier who can give me a hand? smiley
        • 5950
        • 44 Posts
        I’ve figured out where I’m going wrong here. The filenames called include parens ( and ), so phx is choking to death on them. Trying to sort it out now without going through and editing all my resources and filenames...

        Edited to Add: Tested by removing the parens from one filename, still getting the error and the output set for "else".. so while the parens probably aren’t helping, they aren’t the culprit either.
          • 5950
          • 44 Posts
          Still trying, but not getting anywhere. Would really appreciate any insight!

          The error output (Which displays once at the head of the page for each call) is:

          Parse error: syntax error, unexpected ’)’ in /assets/plugins/phx/phx.parser.class.inc.php(226) : eval()’d code on line 1

          Parse error: syntax error, unexpected ’)’ in /assets/plugins/phx/phx.parser.class.inc.php(226) : eval()’d code on line 1

          The snippet (phx:fileExists) is:
          <?php
          condition[] = intval(file_exists($output));
          ?>


          The call is:
          [+phx:if=`products/[*category_code*]/[*product_filename*]_im.pdf`:fileExists:then=`<img src="assets/images/adobelogo.gif" border="0" height="16" /> <a href="products/[*category_code*]/[*product_filename*]_im.pdf">Instruction Manual</a><br />`:else=`Contact Us for Manual<br />`+]
          


          Currently, an example of a file this would check for is http://www.comnet.net/products/Video/FVTFVR100MS1_im.pdf


          Web Server:
          * Network Solutions
          * PHP version 5.2.6 running via CGI
          * Linux vux21 2.6.33.2 Apache/2.2.8 (Unix) (includes FrontPage/5.0.2.2635, not used)

          Database:

          * MySQL version 5.0.75
          * Tables over 1MB in size: fvt_manager_log

          MODx:

          * Version 1.0.2
          * No changes made to the core code
          * Custom phx:fileExists snippet
          * PHx 2.1.3

          Browser/Client:

          * FireFox 3.6.3
          * Mac OS X 10.5.8


          I realize that bS hasn’t been around in 6 months, but I’m hoping someone else has some idea of what’s wrong. The modifier seems so simple I feel like I’m trying to troubleshoot a pushpin. huh
            • 4310
            • 2,310 Posts
            This is untested for your TV’s but based on something I use for checking if a thumbnail is available.
            Create a snippet, (this doesn’t use PHX), named pdf_exists with the following code :
            <?php
            $doc = $modx->getTemplateVarOutput(true, $modx->documentIdentifier);
            $file = 'products/'.$doc['category_code'].'/'.$doc['product_filename'].'_im.pdf';
            if(file_exists($file)){
            $o = '<img src="assets/images/adobelogo.gif" border="0" height="16" /> <a href="'.$file.'">Instruction Manual</a><br />';
            }
            else $o = 'Contact Us for Manual<br />';
            return $o;
            ?>

            Then call it wherever you want the link/text to appear.
            If this is to run inside a Ditto tpl then I have a PHX version.
              • 5950
              • 44 Posts
              Quote from: bunk58 at May 07, 2010, 05:19 PM

              This is untested for your TV’s but based on something I use for checking if a thumbnail is available.
              Create a snippet, (this doesn’t use PHX), named pdf_exists with the following code ...
              Then call it wherever you want the link/text to appear.
              If this is to run inside a Ditto tpl then I have a PHX version.

              This is run from a Chunk, so PHx shouldn’t be necessary.

              Thanks so much for sharing your code and pre-seeding it with my info. It doesn’t output the parse error (yay!) but I’m still having trouble, in that I consistently get the "else" output.

              I tried various versions of the following:

              print_r($modx->getTemplateVarOutput(array["*"], $modx->documentIdentifier));


              The snippet call was at first:

              [!manualLink!]


              I also tried
              [!manualLink? &hiddenfields=`category_code,product_filename`!]


              and still the statement to set $doc isn’t returning anything.

              <?php
              $doc = $modx->getTemplateVarOutput(true, $modx->documentIdentifier);
              $file = 'http://www.comnet.net/products/'.$doc['category_code'].'/'.$doc['product_filename'].'_im.pdf';
              if(file_exists($file)){
              $o = '<img src="assets/images/adobelogo.gif" border="0" height="16" /> <a href="'.$file.'">Instruction Manual</a><br />';
              }
              else $o = 'Contact Us for Manual<br />';
              return $o;
              ?>
                • 4310
                • 2,310 Posts
                Well, it works for me if I substitute your TV’s with mine.
                Try adding print_r($doc); before the return and see what you’ve got in the array, mine had all my TV’s.
                  • 5950
                  • 44 Posts
                  That was the first thing I tried when it didn’t give me the file_exists output.

                  My TVs are set as Text with the HTML Entities Widget. Not sure if that would have any effect, just trying to figure out what the difference is between my recipe and yours.
                    • 5950
                    • 44 Posts
                    Anyone else have any ideas as to how to troubleshoot the fileexists modifier or something similar?