Smarty

Enbici makes extensive usage of smarty to manage its views, and it is one of the main modules in Enbici.

What is Smarty?

Smarty is template engine for PHP. Smarty facilitates a way application logic and presentation can be separated. Therefore, instead of embedding PHP into your view you only pass the information that will be presented to the view, and the view manages it presentation.

With Smarty and Enbici you can easily do something like this.

public function welcomeAction(){
	$this->view->assign('name', 'John Doe');
}

And in the view we will write it like this in order to display it.

Welcome to enbici {$name}

Here we can see there are no PHP tags needed and Smarty is making the view look cleaner and easier to maintain even with this small example.

Now here is another example demonstrating the capabilities of Smarty. Lets say we have to display a list of registered users to the administrator.

public function welcomeAction(){
	$users = User::findAll();
	$this->view->assign('users', $users);
}

Users

    {foreach $users item="user"}
  • {$user->name, $user->address}
  • {foreachelse}
  • No users found
  • {/foreach}

Here we demonstrated the ability of Smarty to take PHP arrays and display them. These are just some of the capabilities of Smarty, if you'd like to learn more about Smarty, which I recommend you should do, please visit their site which contains the documentation on how to use Smarty.

blog comments powered by Disqus