Skip to content

Commit

Permalink
Allow path override in views.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerfinnell committed Jun 15, 2018
1 parent c50eb84 commit 6c11b8b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/class-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,25 @@ public static function watch() {
*
* @since 1.0.0
*
* @param string|array $templates The name of the template.
* @param array $args Variables to pass to partial.
* @param string|array $templates The name of the template.
* @param array $args Variables to pass to partial.
* @param (false|string) $path Optional view base path.
*/
public static function view( $templates, $args = [] ) {
echo self::get_view( $templates, $args, self::$base_path ); // WPCS: XSS okay.
public static function view( $templates, $args = [], $path = false ) {
echo self::get_view( $templates, $args, $path ); // WPCS: XSS okay.
}

/**
* Return a view.
*
* @since 1.0.0
*
* @param string|array $templates The name of the template.
* @param array $args Variables to pass to partial.
* @param string|array $templates The name of the template.
* @param array $args Variables to pass to partial.
* @param (false|string) $path Optional view base path.
* @return string
*/
public static function get_view( $templates, $args = [] ) {
public static function get_view( $templates, $args = [], $path = false ) {
if ( ! is_array( $templates ) ) {
$templates = [ $templates ];
}
Expand All @@ -169,9 +171,13 @@ public static function get_view( $templates, $args = [] ) {

$_templates = [];

if ( ! $path ) {
$path = self::$base_path;
}

foreach ( $templates as $key => $template_name ) {
$_templates[] = $template_name . '.php';
$_templates[] = trailingslashit( self::$base_path ) . $template_name . '.php';
$_templates[] = trailingslashit( $path ) . $template_name . '.php';
}

$template = locate_template( $_templates );
Expand Down

0 comments on commit 6c11b8b

Please sign in to comment.