Skip to content

Instantly share code, notes, and snippets.

@soutar
Last active August 29, 2015 14:07
Show Gist options
  • Save soutar/1105efff53d38eb07d91 to your computer and use it in GitHub Desktop.
Save soutar/1105efff53d38eb07d91 to your computer and use it in GitHub Desktop.
get_template_part_with()
<?php
/**
* This function extends get_template_part to include the ability
* to pass variables to the template file
*
* @param $template_names array|string Either a single template name or an array of template names, ordered by priority
* @param $variables array The variables to make available to the template
*/
function get_template_part_with($template_names, $variables = array()) {
extract($variables);
unset($variables);
if (is_array($template_names)) {
include locate_template($template_names);
} else {
include locate_template(array($template_names));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment