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

    i had a problem today in that i needed to have the tplAlt template used every 4 results rather than the custom 2 (every other). this was for a page of small divs all floated left and to have a clear:both tag after 4 iterations to keep the page nice and tidy.

    if anyone’s interested i solved this by adding a new parameter "&interval"

    in the ditto snippet i added the following at line 705 (just above the $templates):
    $interval = (isset($interval))? $interval : 0;
    /*
    	Param: interval
    
    	Purpose:
    	allows the alternate template to be used at custom intervals
    	rather than the default "every other"
    
    	Options:
    	n - must be > 1
    
    	Default:
    	0 - default every other
    */


    i then passed this new variable to the determine() function at the new line 951:
    $template = $ditto->template->determine($templates,$interval,$x,0,$stop,$resource[$x]["id"]);


    in classes/template.class.inc.php i amended function determine() at line 167 thus:

    	function determine($templates,$interval,$x,$start,$stop,$id) {
    		global $modx;
    
    		// determine current template
    		$currentTPL = "base";
    		if($interval > 1 && !empty($templates["alt"])){
    			if ($x % $interval == ($interval-1)) {
    				$currentTPL = "alt";
    			}
    		}
    		else{
    			if ($x % 2 && !empty($templates["alt"])) {
    				$currentTPL = "alt";
    			}
    		}
    		if ($id == $modx->documentObject['id'] && !empty($templates["current"])){
    			$currentTPL = "current";
    		}
    		if ($x == 0 && !empty($templates["first"])) {
    			$currentTPL = "first";
    		}
    		if ($x == ($stop -1) && !empty($templates["last"])) {
    			$currentTPL = "last";
    		} 
    		$this->current = $currentTPL;
    		return $templates[$currentTPL];
    	}
    


    i hope this is of some use to others out there?

    however, if this functionality already exists and i’ve just completely overlooked it, or if there are some glaring problems here please let me know!!! smiley
      • 18397
      • 3,250 Posts
      This makes sense. Please file a feature request ticket using the link in my signature.