Last active
December 3, 2020 17:06
-
-
Save elliottmangham/3c288cb9477753323b939e821e69e9bf to your computer and use it in GitHub Desktop.
php / utilities
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
/************************************ | |
* Include partial file. | |
* @param string $sFilePath The component to include | |
* @param array $aScopeVariables An array of variables to make available in the component | |
* @param boolean $bReturn Return the markup instead off outputting it? | |
************************************/ | |
function get_partial( $sFilePath, $aScopeVariables = [], $bReturn = false ) { | |
ob_start(); | |
extract( $aScopeVariables, EXTR_OVERWRITE ); | |
$sTemplateSlug = sprintf( '/templates/_partials/%s.php', $sFilePath ); | |
$sTemplateLocation = locate_template( $sTemplateSlug ); | |
if ( ! is_readable( $sTemplateLocation ) ) { | |
throw new \Exception( sprintf( 'Missing partial: %s', $sFilePath ) ); | |
} | |
include $sTemplateLocation; | |
$sComponent = ob_get_clean(); | |
if ( $bReturn === true ) return $sComponent; | |
echo $sComponent; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment