templatePaths = $this->Dispatch->shellPaths; } /** * Find a template * * @param string $directory Subdirectory to look for ie. 'views', 'objects' * @param string $filename lower_case_underscored filename you want. * @access public * @return string filename or false if scan failed. **/ function _findTemplate($directory, $filename) { foreach ($this->templatePaths as $path) { $templatePath = $path . 'templates' . DS . $directory . DS . $filename . '.ctp'; if (file_exists($templatePath) && is_file($templatePath)) { return $templatePath; } } return false; } /** * Set variable values to the template scope * * @param mixed $one A string or an array of data. * @param mixed $two Value in case $one is a string (which then works as the key). * Unused if $one is an associative array, otherwise serves as the values to $one's keys. * @return void */ function set($one, $two = null) { $data = null; if (is_array($one)) { if (is_array($two)) { $data = array_combine($one, $two); } else { $data = $one; } } else { $data = array($one => $two); } if ($data == null) { return false; } foreach ($data as $name => $value) { $this->templateVars[$name] = $value; } } /** * Runs the template * * @param string $directory directory / type of thing you want * @param string $filename template name * @param string $vars Additional vars to set to template scope. * @access public * @return contents of generated code template **/ function generate($directory, $filename, $vars = null) { if ($vars !== null) { $this->set($vars); } if (empty($this->templatePaths)) { $this->initialize(); } $templateFile = $this->_findTemplate($directory, $filename); if ($templateFile) { extract($this->templateVars); ob_start(); ob_implicit_flush(0); include($templateFile); $content = ob_get_clean(); return $content; } return ''; } }