Cake with Smarty(ies)
Joe Topjian propose a possible method for Smarty on the google group. here on some possible modifications.
1) Get the Smarty library
2) Add Smarty to /vendors
Create Component
<?php vendor('Smarty/libs/Smarty.class'); class SmartyComponent extends smarty { var $template_dir = null; var $compile_dir = null; var $cache_dir = null; function startup(&$controller) { if (isset($controller->params['plugin']) && $controller->params['plugin'] != "") { $view_path = ROOT .DS. 'plugins' .DS. strtolower($controller->params['plugin']) .DS. 'views' .DS. strtolower($controller->name) .DS; } else { $view_path = VIEWS . strtolower($controller->name) . DS; } $this->template_dir = $view_path .'smarty'.DS; $this->compile_dir = TMP.DS.'smarty'.DS.'compile'.DS; $this->cache_dir = TMP.DS.'smarty'.DS.'cache'.DS; } } ?>
in your controller
class PostsController extends AppController { var $name = 'Posts'; var $components=array('Smarty'); var $autoRender = false;//make sure cake does not render function index() { $this->Smarty->assign('data', $this->Post->findAll()); $this->Smarty->display('index.tpl'); }
So with the above code the smarty templates would be in /app/views/posts/smarty/index.tpl
the compile directory would be /tmp/smarty/compile/
the cache directory would be /tmp/smarty/cache/
This will give you a basic Smarty set up overriding Cake’s default rendering. Be aware that you won’t have access to scaffolding, the html helper, and other Cake view features. However, Smarty is a very fast, elegant, and easy to use template language – so give it a shot!
Installation Bugg Reports
RC6 Check cake/basics.php vendor() function, if(file_exists(APP.’vendors’.DS.$arg.php))
–> Remove ‘.php’ if necessary so that it reads: if(file_exists( APP.’vendors’.DS.$arg ))
RC6 Verify Component has correct directory structure (remove ‘DS’ if necessary): $this→template_dir = VIEWS.DS.$viewDir.DS.’smarty’.DS;
–>Remove ‘.DS’ if necessary so that it reads: $this→template_dir = VIEWS.$viewDir.DS.’smarty’.DS;