public function template($data = array(), $name = 'template') { static $template = array(); if (Templates::is_absolute_path($name)) { return $name; } if (isset($data['template'])) { $data_templates = is_string($data['template']) ? array('template' => $data['template']) : $data['template']; if (isset($data_templates[$name]) && IO_FS::exists($data_templates[$name])) { return $data_templates[$name]; } } $type = isset($data['type']) ? $data['type'] : 'input'; $key = $type . '_' . $name; if (isset($template[$key])) { return $template[$key]; } /*if ($name == 'template' && isset($data['template name'])) $name = $data['template name'];*/ $file = $this->dir() . "/{$name}.phtml"; if (IO_FS::exists($file)) { return $template[$key] = $file; } $types = array($type); $parents = Core_Types::class_hierarchy_for($this); if (count($parents) >= 3) { foreach (array_slice($parents, 1, count($parents) - 2) as $p) { $type = CMS_Fields::type_by_class($p); if (empty($type)) { $type = CMS_Fields::type_by_class(Core_Types::module_name_for($p)); } $types[] = $type; } } foreach ($types as $t) { if (empty($t)) { continue; } $view = Templates_HTML::Template('fields/' . $t . '/' . $name); if ($view->exists()) { return $template[$key] = $view->path; } } $view = Templates_HTML::Template('fields/' . $name); if ($view->exists()) { return $template[$key] = $view->path; } return $template[$key] = $name; }