Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elieandraos/5813200 to your computer and use it in GitHub Desktop.
Save elieandraos/5813200 to your computer and use it in GitHub Desktop.
Symfony Like include_partial functionality
/* PARTIAL_DIR is a constant that defines the path of the partial file to include */
function get_partial($partialName, $vars = array()){
// start the output buffer
ob_start();
ob_implicit_flush(0);
// extract the variables in the scope of this function
extract($vars);
// include the file
include PARTIAL_DIR.$partialName.'.php';
// clear the output buffer, and return the content
return ob_get_clean();
}
/*
* used to include compoments with the ability to pass variables to them
*/
function include_partial($partialName, $vars = array()){
echo get_partial($partialName, $vars);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment