Created
June 19, 2013 10:05
-
-
Save elieandraos/5813200 to your computer and use it in GitHub Desktop.
Symfony Like include_partial functionality
This file contains 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 characters
/* 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