public function template($template_name, $code = null, $deprecated = false)
{
$out = null;
$obj =& $this;
if (!empty($code)) {
$code = str_replace('$this->', '$obj->', $code);
// backwards compatibility
$code = apply_filters('pods_templates_pre_template', $code, $template_name, $this);
$code = apply_filters("pods_templates_pre_template_{$template_name}", $code, $template_name, $this);
ob_start();
if (!empty($code)) {
// Only detail templates need $this->id
if (empty($this->id)) {
while ($this->fetch()) {
echo $this->do_magic_tags($code);
}
} else {
echo $this->do_magic_tags($code);
}
}
$out = ob_get_clean();
$out = apply_filters('pods_templates_post_template', $out, $code, $template_name, $this);
$out = apply_filters("pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this);
} elseif (class_exists('Pods_Templates')) {
$out = Pods_Templates::template($template_name, $code, $this, $deprecated);
} elseif ($template_name == trim(preg_replace('/[^a-zA-Z0-9_\\-\\/]/', '', $template_name), ' /-')) {
ob_start();
$default_templates = array('pods/' . $template_name, 'pods-' . $template_name, $template_name);
$default_templates = apply_filters('pods_template_default_templates', $default_templates);
// Only detail templates need $this->id
if (empty($this->id)) {
while ($this->fetch()) {
pods_template_part($default_templates, compact(array_keys(get_defined_vars())));
}
} else {
pods_template_part($default_templates, compact(array_keys(get_defined_vars())));
}
$out = ob_get_clean();
$out = apply_filters('pods_templates_post_template', $out, $code, $template_name, $this);
$out = apply_filters("pods_templates_post_template_{$template_name}", $out, $code, $template_name, $this);
}
return $out;
}