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

    I’ve tried really hard with this one, reading and re-reading the documentation and examples, doing 10s of searches on the forums and simplifying my code, all so far to no avail.

    I want to use ditto to filter based on 2 clauses with an AND relationship. As I understand it the only way to do this is using extenders. I have created a file called:

    directors.extender.inc.php

    which contains the following code:

    <?php
    echo "test in extender";
    $filters["custom"]["directorsFilter"] = array("projectElementShowInDirectorList,projectElementDirector","directorsFilter"); 
    
    if (!function_exists("directorsFilter")) {
    	function directorsFilter($resource) {
                    echo "test in function";
    		if ($resource['projectElementShowInDirectorList'] == "yes" && $resource['projectElementDirector'] != "") {
    			return 0;
    		} else {
    			return 1;
    		}
    	}
    }
    ?>
    


    Here is my ditto call:

    [!Ditto?parents=`2`&hideFolders=`1`&depth=`2`&sortBy=`menuindex`&sortDir=`ASC`&display=`all`&extenders=`directors`&tpl=`mychunk`&debug=`1`!]
    


    Notice the two echo calls. The first one that echos "test in extender" is echoed to screen so I know that the extender is being loaded. The second one that echos "test in function" does not appear, telling me that the function never gets called.

    I’m wondering if there is something else in my ditto call that prevents the custom filter being called. I’ve played around with other parameters but nothing gives me the results I expect, I always get all the data.

    projectElementShowInDirectorList is a checkbox tv with a input value of ’yes’ and a default value of ’no’.
    projectElementDirector is a dropdown tv and contains a string value.

    I am using ditto version 2.0.2 and modx version 0.9.6.1 and php version 5.2

    Any help or work-a-rounds would be very appreciated
      Hmmmmm.

      It&#39;s all a delusion
      • 18397
      • 3,250 Posts
      An echo call within a filter will not output as the function is being called by a callback.

      Here are a few things you can try:
      1. Swapping the 0 and 1 in the return statements
      2. Installing Ditto 2.1b4 as it contains numerous bugfixes
      3. Attach the debug output of your call (See the [Policy] thread stickied in this forum) to your post
        • 1634
        • 51 Posts
        Hi Mark,

        Thanks for your reply. I’m attaching the debug to this message. I’ve tried swapping the 1 and 0, same result. I’m going to upgrade ditto now.

        AndyFlan
          Hmmmmm.

          It&#39;s all a delusion
          • 1634
          • 51 Posts
          Hi,

          Am very pleased to inform you that the upgrade worked and now my custom filter is getting called and working as expected.

          Quote from: Mark at Feb 02, 2008, 05:56 PM

          An echo call within a filter will not output as the function is being called by a callback.

          It would seem that this is not the case, my test echo call IS now being called. Thanks for your input.

          AndyFlan
            Hmmmmm.

            It&#39;s all a delusion