tags:

views:

64

answers:

3

Besides the existence of Smarty.class.php (which is also arguable), how do we know that a php project is using smarty template framework just by looking at its file structure?

+1  A: 

I think you can figure it out via checking the basic view class.E.g

class View
{
    protected $tpl;
    protected $tplfilename;

    public function __construct()
    {
        $this->tpl = new Smarty();

        $this->tpl->template_dir = dirname(__FILE__)."/templates"; 
        $this->tpl->compile_dir = dirname(__FILE__)."/templates_c"; 
        $this->tpl->config_dir = dirname(__FILE__)."/configs"; 
        $this->tpl->cache_dir = dirname(__FILE__)."/cache"; 
        $this->tpl->left_delimiter = "{|";
        $this->tpl->right_delimiter = "|}";

        $this->tplfilename = "default.tpl";
    }

    public function show()
    {
        $this->tpl->display($this->tplfilename);
    }
}

This should probably be a typical smarty style.

SpawnCxy
Not all projects are OOP based or use the MVC approach. Though i think it wud be better if they did ;)..
pinaki
@pinaki True,then it will be difficult to do know this cuz most directories in smarty are configurable.
SpawnCxy
Since a compile_dir is required one could look for one of two things: the presence of the default 'templates_c' folder or a line containing '->compile_dir'.
djn
+3  A: 

Usually well-structured projects will have a template and template_c folder - although the names can be configured/changed. Additionally look for .tpl files in these folders.

The best approach I can see is to grep for common smarty functions like fetch/assign/display or common smarty tags like {foreach}, {assign}, {if}, etc.

pinaki
+2  A: 

You might need to poke around to find the templates and templates_c - in one of my projects they're not even in htdocs - the smarty folder is at the same level as htdocs. And we named our Smarty class based on the project, so even looking for "new Smarty()" wouldn't work.

I think the first answer that recommend looking for common smarty functions might be your best bet.

NatalieL