Passing variables through locate_template

Like MathSmath wrote, get_template() does not support the re-use of your variables.

But locate_template() infact does no inclusion at all. It just locates a file for inclusion.

So you can make use of include to have this working just like you expect it:

include(locate_template('custom-template-part.php'));

$var from your example can be used in the template part then.

A related question with a more technical explanation of the variable scope and get_template(): Form Submitting Error with get_template_part()

Leave a Comment