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

    I’ve been searching in the forum for some time now and found a solution to my problem smiley

    So, after applying the solution it didn’t work - so again after researching further I found another solution but that doesn’t work properly either (with my setup).

    I am trying to get the "Ditto Extender: countDocs" to work whilst using the "Phx Plugin" at the same time.

    When Phx is disabled the extender works perfectly - but yes, as soon as its activated all goes to the dogs.

    The following is the output from Ditto when Phx is activated:


    &tpl either does not contain any placeholders or is an invalid name, code block, or filename. Please check it.

    If anyone has an idea to solve this problem, that would be great.

    My Ditto call:

    [[Ditto? &extenders=`countDocs` &display=`1` &parents=`3,4` &depth=`2` &tpl=`@CODE Total Documents: [+count+]` &hideFolders=`1` &showInMenuOnly=`0` &showPublishedOnly=`1`]]
    


    Ditto Extender:

    <?php
    /*
     * Ditto Extender: countDocs
     * Counts documents returned by Ditto
     * Copyright (c) 2009-2010 Aleksander Maksymiuk, http://setpro.net.pl/
     * Parameters:
     * 	no parameters required
     * Example: count documents within 3, 4, and 5 containers
     * 	[[Ditto? &parents=`3,4,5` &extenders=`countDocs` &display=`1` &tpl=`@CODE:[+count+]`]]
     * Please notice in the above example 'display' parameter set to 1 -> it was done
     * because 'count' placeholder is set to each document within result set while we (most likely)
     * need this value to be returned only once
     */
    
    $GLOBALS['docCounter'] = 0;
    
    $filters['custom']['countDocs'] = array('id', 'countDocuments');
    
    if (!function_exists('countDocuments')) {
    	function countDocuments($resource) {
    		# count documents
    		$GLOBALS['docCounter']++;
    		return 1;
    	}
    }
    
    $placeholders['count'] = array('id', 'setCountPlaceholder');
    
    if (!function_exists('setCountPlaceholder')) {
    	function setCountPlaceholder($resource) {
    		return $GLOBALS['docCounter'];
    	}
    }
    
    ?>
    
    • The phx plugin eats placeholders. If you are only using phx in Ditto tpls, you don’t need the plugin as Ditto has the phx class included internally.

      If you must use phx in your site in general, the only solution is to make a snippet and fetch the placeholder yourself from the $modx->placeholders[’placeholder-name’] array. The placeholder’s value is still in the array, it’s just that the phx garbage collection function removes the tags from the content.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 36416
        • 589 Posts
        Quote from: iusemodx at Aug 03, 2011, 05:12 PM

        I am trying to get the "Ditto Extender: countDocs" to work whilst using the "Phx Plugin" at the same time.
        When Phx is disabled the extender works perfectly - but yes, as soon as its activated all goes to the dogs.

        Put Ditto template in config file and PHx will stop "eating" it:
        http://ditto.modxcms.com/files/snippet-ditto-php.html#config
          • 13226
          • 953 Posts
          @ sottwell + Eol

          Thanks for your answers

          Sadly Im not a PHP guru and to be honest I don’t understand what is meant with using the config file.

          I need "Phx" as standalone as I use it in the templates - the site had 10 templates, now with the help of the Phx plugin I have 3.

          I was looking to use Ditto as its part of the download package and supported by the Modx Team and the community.

          Cheers