I’ve been searching for a solution to send variable in “get_template_part” function and always without luck. I personally don’t like to use global variables because I know, this is just a bad practice. A few months ago I’ve been able to design a solution that pass Theme Check and has support for child themes. I think is a good idea to share with TF authors.
Smartik why dont use include( locate_template( ‘template-part.php’ ) ); ? It is simplest…
Check the code that I’ve shared. I use include and I do also some additional checks to make sure it does not break anything. Also usign direct include is not allowed by ThemeForest because Theme Check will detect it as a warning.
A posible solution is this
ob_start();
smk_get_template_part(
LOCATION OF YOUR FILE OR TEMPLATE,
array(
‘data_1’ => $variable,
'data_2 => 3,
‘data_3’ => ‘someone here’
)
);
$variable_template = ob_get_contents();
ob_end_clean();