Rendering template functionrender_template ($ template_file, $ variables) {extract ($ variables, EXTR_SKIP); extract (); Startoutputbufferinginclude. $ template_file; Includethetemplatefile $ c
Rendering template function render_template ($ template_file, $ variables) {extract ($ variables, EXTR_SKIP); // Extract the variables to a local namespace ob_start (); // Start output buffering include ". /$ template_file "; // Include the template file $ c
Rendering Template
function render_template($template_file, $variables) { extract($variables, EXTR_SKIP); // Extract the variables to a local namespace ob_start(); // Start output buffering include "./$template_file"; // Include the template file $contents = ob_get_contents(); // Get the contents of the buffer ob_end_clean(); // End buffering and discard return $contents; // Return the contents}
Usage
$render_message = array( 'token' => $token, 'me' => $user, 'game_key' => $game_key, 'game_link' => $game_link, 'initial_message' => $initial_message, );$template_file = 'index.tpl';$ret = render_template($template_file, $render_message);echo($ret);
Original article address: PHP simple rendering template. Thank you for sharing it.