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

    How to use @CODE on &tpl and other params on Ditto?


    José Moreira
      • 4310
      • 2,310 Posts
      <?php
      $params['startID'] = 2;
      $params['display'] = 'all';
      $params['tpl'] = '@CODE:<p> [+introtext+]</p>';
      $params['sortDir'] = 'DESC';
      $params['depth'] = 1;
      $params['noResults'] = ' ';
      $params['showInMenuOnly'] = 1;
      $output = $modx->runSnippet('Ditto', $params);
      return $output;
      ?>
        • 2819
        • 30 Posts
        Indeed that ’s it ... what I wonder about is why you can only use @CODE when using the ditto snippet in another snippet through runSnippet .. and not in a regular call huh ?

        like this :

        [!Ditto? &id=`test` &parents=`8,23` &depth=`1` &display=`all` &tpl=`@CODE:[+id+], ` &debug=`1`!]


        I tried many times, but i always get
        "&tpl either does not contain any placeholders or is an invalid chunk name, code block, or filename. Please check it."

        It does contain placeholder ....

        looking in template.class.inc.php (included in assets/snippets/dito/classes directory I see:
        	function fetch($tpl){
        		global $modx;
        		$template = "";
        		if ($modx->getChunk($tpl) != "") {
        			$template = $modx->getChunk($tpl);
        		} else if(substr($tpl, 0, 6) == "@FILE:") {
        			$template = $this->get_file_contents(substr($tpl, 6));
        		} else if(substr($tpl, 0, 6) == "@CODE:") {
        			$template = substr($tpl, 6);
        		} else if(substr($tpl, 0, 5) == "@FILE") {
        			$template = $this->get_file_contents(trim(substr($tpl, 5)));
        		} else if(substr($tpl, 0, 5) == "@CODE") {
        			$template = trim(substr($tpl, 5));
        		} else {
        			$template = $this->language['missing_placeholders_tpl'];
        		}
        			return $template;
        	}


        So I think it should work ...

        but i think it goes wrong at line 38 of the same file ...
        	function process($template) {
        		if (!isset($template["base"])) {
        			$template["base"] = $template["default"];
        		} else {
        			unset($template["default"]);
        		}
        		foreach ($template as $name=>$tpl) {
        			if(!empty($tpl) && $tpl != "") {
        				$templates[$name] = $this->fetch($tpl);
        			}
        		}
        		$fieldList = array();
        		foreach ($templates as $tplName=>$tpl) {
        			$check = $this->findTemplateVars($tpl);
        			if (is_array($check)) {
        				$fieldList = array_merge($check, $fieldList);
        			} else {
        				switch ($tplName) {
        					case "base":
        						$displayName = "tpl";
        					break;
        					
        					case "default":
        						$displayName = "tpl";
        					break;
        					
        					default:
        						$displayName = "tpl".$tplName;
        					break;
        				}
        				$templates[$tplName] = str_replace("[+tpl+]",$displayName,$this->language["bad_tpl"]);
        			}
        		}