-
-
Save rossberenson/3d9aee7e21c5666a38e8fafbcffc9bbf to your computer and use it in GitHub Desktop.
Get Template Part With Arguments ( Forked incase if author removes it )
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 rb_get_template_part($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