-
-
Save geomorillo/80ea53b8d0ee64c941659e924335ff59 to your computer and use it in GitHub Desktop.
Revisions
-
ziadoz revised this gist
Apr 1, 2013 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,6 @@ function parse_template($template, $data) { $output = parse_template($template, array( 'title' => 'Hello, World!', 'paragraph' => 'This is an exciting paragraph of text.', )); echo $output; -
ziadoz revised this gist
Apr 1, 2013 . 1 changed file with 15 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,28 +9,28 @@ * http://php.net/manual/en/function.halt-compiler.php */ function get_halt_data() { return file_get_contents(__FILE__, false, null, __COMPILER_HALT_OFFSET__); } function create_tmp_template($data) { $tmpfile = tempnam(sys_get_temp_dir(), 'halt_compiler_template'); file_put_contents($tmpfile, $data); return $tmpfile; } function parse_template($template, $data) { $data = (array) $data; ob_start(); extract($data); include $template; return ob_get_clean(); } $template = create_tmp_template(get_halt_data()); $output = parse_template($template, array( 'title' => 'Hello, World!', 'paragraph' => 'This is an exciting paragraph of text.', )); @@ -43,11 +43,11 @@ function parse_template($template, $data) { <!DOCTYPE> <html> <head> <meta charset="utf-8" /> <title><?php echo $title; ?></title> </head> <body> <h1><?php echo $title; ?></h1> <p><?php echo $paragraph; ?></p> </body> </html> -
ziadoz revised this gist
Apr 1, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ /** * The __halt_compiler() function will stop the PHP compiler when called. * You can then use the __COMPILER_HALT_OFFSET__ constant to grab the contents of the PHP file after the halt. * In this example a PHP template is stored after the halt, to allow simple separation of logic from templating. * The template is stored in a temporary file so it can be included and parsed. * * See: https://github.com/bobthecow/mustache.php/blob/dev/src/Mustache/Loader/InlineLoader.php -
ziadoz created this gist
Apr 1, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ <?php /** * The __halt_compiler() function will stop the PHP compiler when called. * You can then use the __COMPILER_HALT_OFFSET__ constant to grab the contents of the PHP file after the halt. * In this example a simple PHP template is stored after the halt, to allow simple separation of logic from templating. * The template is stored in a temporary file so it can be included and parsed. * * See: https://github.com/bobthecow/mustache.php/blob/dev/src/Mustache/Loader/InlineLoader.php * http://php.net/manual/en/function.halt-compiler.php */ function get_halt_data() { return file_get_contents(__FILE__, false, null, __COMPILER_HALT_OFFSET__); } function create_tmp_template($data) { $tmpfile = tempnam(sys_get_temp_dir(), 'halt_compiler_template'); file_put_contents($tmpfile, $data); return $tmpfile; } function parse_template($template, $data) { $data = (array) $data; ob_start(); extract($data); include $template; return ob_get_clean(); } $template = create_tmp_template(get_halt_data()); $output = parse_template($template, array( 'title' => 'Hello, World!', 'paragraph' => 'This is an exciting paragraph of text.', )); echo $output; unlink($template); __halt_compiler(); <!-- Layout Template --> <!DOCTYPE> <html> <head> <meta charset="utf-8" /> <title><?php echo $title; ?></title> </head> <body> <h1><?php echo $title; ?></h1> <p><?php echo $paragraph; ?></p> </body> </html>