Return to Snippet

Revision: 5176
at February 16, 2008 07:44 by chucktrukk


Initial Code
/*	Parse all TVs in the [content] of a document. $doc_id is the id of the document	*/
function mergeDocumentContentX($doc_id) {
		global $modx;
		
		$my_doc = $modx->getTemplateVarOutput('*',$doc_id);
		$template = $my_doc['content'];

		$replace= array ();
		preg_match_all('~\[\*(.*?)\*\]~', $template, $matches);
		$variableCount= count($matches[1]);
		$basepath= $modx->config["base_path"] . "manager/includes";
		for ($i= 0; $i < $variableCount; $i++) {
				$key= $matches[1][$i];
				$key= substr($key, 0, 1) == '#' ? substr($key, 1) : $key; // remove # for QuickEdit format
				$value = $my_doc[$key];
				if (is_array($value)) {
						include_once $basepath . "/tmplvars.format.inc.php";
						include_once $basepath . "/tmplvars.commands.inc.php";
						$w= "100%";
						$h= "300";
						$value= $modx->getTVDisplayFormat($value[0], $value[1], $value[2], $value[3], $value[4]);
				}
				$replace[$i]= $value;
		}
		$template= str_replace($matches[0], $replace, $template);
		//return $template;
		
		$return_vals = array("my_doc" => $my_doc, "template" => $template);
		return $return_vals;
}

Initial URL


Initial Description


Initial Title
mergeDocumentContentX

Initial Tags
php, textmate, template

Initial Language
PHP