private function render() {
		$strings = implode($this->strings);
		
		// Render includes
		foreach ($this->incTemplates as $path => $include) {
			$incOutput = $include->render();
			$path = preg_replace("/\//", "\/", $path);
			$strings = preg_replace("/\{include\s$path\}/", $incOutput, $strings);
		}
		
		// Render if-statements
		foreach ($this->ifTemplates as $key => $sub) {
			foreach ($sub as $iKey => $instance) {
				$str = '';
				
				if ($this->expressions[$key]->evaluate($this->vars)) {
					$str = $instance->render();
				}
				
				$pregKey = preg_quote($key, '/');
				$strings = preg_replace("/\{if:$pregKey:$iKey\}/", $str, $strings);
			}
		}
		
		// Render foreach-loops
		foreach ($this->forTemplates as $key => $sub) {
			foreach ($sub as $iKey => $instance) {
				$tmplGen = '';
				
				if (isset($this->vars[$key]) && is_array($this->vars[$key])) {
					foreach ($this->vars[$key] as $assocArray) {
						foreach ($assocArray as $k => $v)
							$instance->set($k, $v);
						$tmplGen .= $instance->render();
					}
				}
				
				$pregKey = preg_quote($key, '/');
				$strings = preg_replace("/\{for:$pregKey:$iKey\}/", $tmplGen, $strings);
			}
		}
		
		// Render plain old variables
		foreach ($this->vars as $key => $val) {
			if (!is_array($val))
				$strings = preg_replace("/\{$key\}/", $val, $strings);
		}
		
		// Render expressions
		foreach ($this->expressions as $key => $expr) {
			$eval = $expr->evaluate($this->vars);

			// If we're an array, lets insert the number of items in the array.
			if ( is_array( $eval ) ) {
				$eval = count( $eval );
			}

			$pregKey = preg_quote($key, '/');
			
			$strings = preg_replace('/\{'.$pregKey.'\}/', $eval, $strings);
		}
		
		$strings = preg_replace("/\\\{/", '{', $strings);
		$strings = preg_replace("/\\\}/", '}', $strings);

		return $strings;
	}
private function render() {
		$strings = implode($this->strings);
		
		// Render includes
		foreach ($this->incTemplates as $path => $include) {
			$incOutput = $include->render();
			$path = preg_replace("/\//", "\/", $path);
			$strings = preg_replace("/\{include\s$path\}/", $incOutput, $strings);
		}
		
		// Render if-statements
		foreach ($this->ifTemplates as $key => $sub) {
			foreach ($sub as $iKey => $instance) {
				$str = '';
				
				if ($this->expressions[$key]->evaluate($this->vars)) {
					$str = $instance->render();
				}
				
				$pregKey = preg_quote($key, '/');
				$strings = preg_replace("/\{if:$pregKey:$iKey\}/", $str, $strings);
			}
		}
		
		// Render foreach-loops
		foreach ($this->forTemplates as $key => $sub) {
			foreach ($sub as $iKey => $instance) {
				$tmplGen = '';
				
				if (isset($this->vars[$key]) && is_array($this->vars[$key])) {
					foreach ($this->vars[$key] as $assocArray) {
						foreach ($assocArray as $k => $v)
							$instance->set($k, $v);
						$tmplGen .= $instance->render();
					}
				}
				
				$pregKey = preg_quote($key, '/');
				$strings = preg_replace("/\{for:$pregKey:$iKey\}/", $tmplGen, $strings);
			}
		}
		
		// Render plain old variables
		foreach ($this->vars as $key => $val) {
			if (!is_array($val))
				$strings = preg_replace("/\{$key\}/", $val, $strings);
		}
		
		// Render expressions
		foreach ($this->expressions as $key => $expr) {
			$eval = $expr->evaluate($this->vars);

			// If we're an array, lets insert the number of items in the array.
			if ( is_array( $eval ) ) {
				$eval = count( $eval );
			}

			$pregKey = preg_quote($key, '/');
			
			$strings = preg_replace('/\{'.$pregKey.'\}/', $eval, $strings);
		}
		
		$strings = preg_replace("/\\\{/", '{', $strings);
		$strings = preg_replace("/\\\}/", '}', $strings);

		return $strings;
	}
private function render ( ) { $ strings = implode ( $ this -> strings ) ; // Render includes foreach ( $ this -> incTemplates as $ path => $ include ) { $ incOutput = $ include -> render ( ) ; $ path = preg_replace ( "/\//" , "\/" , $ path ) ; $ strings = preg_replace ( "/\{include\s$path\}/" , $ incOutput , $ strings ) ; } // Render if-statements foreach ( $ this -> ifTemplates as $ key => $ sub ) { foreach ( $ sub as $ iKey => $ instance ) { $ str = '' ; if ( $ this -> expressions [ $ key ] -> evaluate ( $ this -> vars ) ) { $ str = $ instance -> render ( ) ; } $ pregKey = preg_quote ( $ key , '/' ) ; $ strings = preg_replace ( "/\{if:$pregKey:$iKey\}/" , $ str , $ strings ) ; } } // Render foreach-loops foreach ( $ this -> forTemplates as $ key => $ sub ) { foreach ( $ sub as $ iKey => $ instance ) { $ tmplGen = '' ; if ( isset ( $ this -> vars [ $ key ] ) && is_array ( $ this -> vars [ $ key ] ) ) { foreach ( $ this -> vars [ $ key ] as $ assocArray ) { foreach ( $ assocArray as $ k => $ v ) $ instance -> set ( $ k , $ v ) ; $ tmplGen .= $ instance -> render ( ) ; } } $ pregKey = preg_quote ( $ key , '/' ) ; $ strings = preg_replace ( "/\{for:$pregKey:$iKey\}/" , $ tmplGen , $ strings ) ; } } // Render plain old variables foreach ( $ this -> vars as $ key => $ val ) { if ( ! is_array ( $ val ) ) $ strings = preg_replace ( "/\{$key\}/" , $ val , $ strings ) ; } // Render expressions foreach ( $ this -> expressions as $ key => $ expr ) { $ eval = $ expr -> evaluate ( $ this -> vars ) ; // If we're an array, lets insert the number of items in the array. if ( is_array ( $ eval ) ) { $ eval = count ( $ eval ) ; } $ pregKey = preg_quote ( $ key , '/' ) ; $ strings = preg_replace ( '/\{' . $ pregKey . '\}/' , $ eval , $ strings ) ; } $ strings = preg_replace ( "/\\\{/" , '{' , $ strings ) ; $ strings = preg_replace ( "/\\\}/" , '}' , $ strings ) ; return $ strings ; }
The render function goes through and renders the parsed document.

@return string containing the rendered output.
The render function goes through and renders the parsed document .