Created
September 8, 2016 20:45
-
-
Save jo-flynn/49e5cca345458b336500bf5ab48bd6f1 to your computer and use it in GitHub Desktop.
silencio_partial
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
<?php | |
/** | |
* Load a template part & pass in variables declared in caller scope. Optionally return as a string. | |
* @param string $path path to template file, minus .php (eg. `content-page`, `partial/folder/template-name`) | |
* @param array $args map of variables to load into scope | |
* @param bool $echo echo or return rendered template | |
* @return null or rendered template string | |
*/ | |
function silencio_partial($path, $args = [], $echo = true) { | |
if (!empty($args)) { | |
extract($args); | |
} | |
if ($echo) { | |
include(locate_template($path . '.php')); | |
return; | |
} | |
ob_start(); | |
include(locate_template($path . '.php')); | |
return ob_get_clean(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment