Skip to content

Instantly share code, notes, and snippets.

@jo-flynn
Created September 8, 2016 20:45
Show Gist options
  • Save jo-flynn/49e5cca345458b336500bf5ab48bd6f1 to your computer and use it in GitHub Desktop.
Save jo-flynn/49e5cca345458b336500bf5ab48bd6f1 to your computer and use it in GitHub Desktop.
silencio_partial
<?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