diff --git a/views/Template.class.inc.php b/views/Template.class.inc.php new file mode 100644 index 0000000..70947b3 --- /dev/null +++ b/views/Template.class.inc.php @@ -0,0 +1,89 @@ +template = file_get_contents( $path ); + + } # function __construct(...) + + /** + * Replaces a placeholder with a string + * + * @param string $a_key Key of the placeholder + * @param string $a_value Replace this with the key + * + * @throws Exception Wirft Exception + * @return void + * + */ + public function set_placeholder( $a_key, $a_value ) + { + if ( empty( $a_value ) ) + { + $a_value = '-'; + } + $a_key = mb_strtoupper( $a_key ); + $key = '[[' . $a_key . ']]'; + + $this->template = str_replace( $key, $a_value, $this->template ); + + } # function set_placeholder(...) + + /** + * Removes all unused placeholders + * + * @return void + */ + private function removePlaceholder() + { + $this->template = preg_replace( '/\[\[.*]]/', '', $this->template ); + + } # function removePlaceholder() + + /** + * Return the template as string + * + * @return string + */ + public function getHtml() + { + # Remove all unreplaced placeholders + $this->removePlaceholder(); + + return $this->template; + + } # function getHtml() + + + + +} # class \ No newline at end of file