Revision: 10483
Updated Code
at January 1, 2009 11:34 by Jdub7
Updated Code
<?php function apply_template($file,$vars=array(),$include_globals=false){ extract($vars); if($include_globals){ extract($GLOBALS, EXTR_SKIP); } ob_start(); require($file); $template_html = ob_get_contents(); header('Content-Length: ' . ob_get_length()); ob_end_clean(); return $template_html; } $template_vars['title'] = 'Hello World!'; $template_vars['text'] = 'Hello World!'; $template_vars['links'] = array( 'http://www.bigsmoke.us/php-templates/functions', 'http://www.php.net/' ); $html = apply_template("_main.tpl.php",$template_vars); echo $html; /////////////////// // _main.tpl.php // /////////////////// /* <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php echo $title; ?></title> <link rel="shortcut icon" type="image/png" href="favicon.png" /> <link rel="stylesheet" href="./css/reset.css" type="text/css" media="all" /> <link rel="stylesheet" href="./css/text.css" type="text/css" media="all" /> <link rel="stylesheet" href="./css/style.css" type="text/css" media="screen, projection" /> <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" /> <!--[if IE]> <link rel="stylesheet" href="./css/ie.css" type="text/css" media="screen, projection" /> <![endif]--> <link rel="script" href="./scripts/javascript.js" type="text/javascript" /> </head> <body> <p><?php echo $text; ?></p> <ul> <?php foreach($links as $link): ?> <li><a href="<?php echo $link; ?>" title="A Link"><?php echo $link; ?></li> <?php endforeach; ?> </ul> </body> </html> */ ?>
Revision: 10482
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 1, 2009 09:34 by Jdub7
Initial Code
function apply_template($file,$vars=array(),$include_globals=false){ extract($vars); if($include_globals){ extract($GLOBALS, EXTR_SKIP); } ob_start(); require($file); $template_html = ob_get_contents(); header('Content-Length: ' . ob_get_length()); ob_end_clean(); return $template_html; } $template_vars['title'] = 'Hello World!'; $template_vars['text'] = 'Hello World!'; $template_vars['links'] = array( 'http://www.bigsmoke.us/php-templates/functions', 'http://www.php.net/' ); $html = apply_template("_main.tpl.php",$template_vars); echo $html; /////////////////// // _main.tpl.php // /////////////////// /* <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php echo $title; ?></title> <link rel="shortcut icon" type="image/png" href="favicon.png" /> <link rel="stylesheet" href="./css/reset.css" type="text/css" media="all" /> <link rel="stylesheet" href="./css/text.css" type="text/css" media="all" /> <link rel="stylesheet" href="./css/style.css" type="text/css" media="screen, projection" /> <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" /> <!--[if IE]> <link rel="stylesheet" href="./css/ie.css" type="text/css" media="screen, projection" /> <![endif]--> <link rel="script" href="./scripts/javascript.js" type="text/javascript" /> </head> <body> <p><?php echo $text; ?></p> <ul> <?php foreach($links as $link): ?> <li><a href="<?php echo $link; ?>" title="A Link"><?php echo $link; ?></li> <?php endforeach; ?> </ul> </body> </html> */
Initial URL
http://www.bigsmoke.us/php-templates/functions
Initial Description
Initial Title
Pure PHP template function
Initial Tags
php, template
Initial Language
PHP