The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Best templating engine for php
Discuss Best templating engine for php in the PHP Development forum on Dev Shed. Best templating engine for php PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 17th, 2012, 10:10 PM
|
 |
A Change of Season
|
|
|
|
|
Best templating engine for php
This is one of those topics that I see so many different opinions on!
I use Codeigniter now and I am doing a research which templating engine suits the best. I haven't found 2 post that have the same opinion! Some say smarty is gold some say stay away from it. Same with Rain tpl, twig,...
I was wondering if you could write your comments on this.
Thanks
|

November 18th, 2012, 07:44 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
Hi,
there is no "best template engine". Some are more user friendly than others, some are faster, some use less memory, some are simpler etc.
I'd go with one of the mainstream engines (Smarty, Twig, ...) that have been proven to work and then simply choose the one you like best. If performance is very important to you, you might also google for benchmarks.
|

November 18th, 2012, 06:44 PM
|
 |
A Change of Season
|
|
|
|
Quote: | Originally Posted by Jacques1 Hi,
there is no "best template engine". Some are more user friendly than others, some are faster, some use less memory, some are simpler etc.
I'd go with one of the mainstream engines (Smarty, Twig, ...) that have been proven to work and then simply choose the one you like best. If performance is very important to you, you might also google for benchmarks. | Thanks I made up my mind. I am going to learn Smarty.
Benefits:
- It seems to be important to large companies in case I want to look for job in future,
- It is another skill,
- And it is always good to learn something new,
- It is well known ( as you mentioned),
Saying that I still think the messy code in inevitable.
PHP Code:
{foreach $foo as $bar}
<a href="{$bar.zig}">{$bar.zag}</a>
<a href="{$bar.zig2}">{$bar.zag2}</a>
<a href="{$bar.zig3}">{$bar.zag3}</a>
{foreachelse}
//OR
{foreach $foo as $bar}
{if $bar@iteration is div by 4}
</tr><tr>
{/if}
<td>{$bar}</td>
{/foreach}
There were no rows found.
{/foreach}
|

November 18th, 2012, 07:11 PM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
Quote: | Originally Posted by zxcvbnm Thanks I made up my mind. I am going to learn Smarty. |
Sounds good.
Quote: | Originally Posted by zxcvbnm Saying that I still think the messy code in inevitable. |
Well, I don't find this example all that terrible. And you'll rarely need stuff like "... @iteration is div by ...", since the structure should already be given by the model.
But sure, you'll never be able to avoid "messy" templates completely. It simply comes with complexity.
|

November 20th, 2012, 04:07 AM
|
 |
A Change of Season
|
|
|
|
Quote: | Originally Posted by Jacques1 Sounds good.
Well, I don't find this example all that terrible. And you'll rarely need stuff like "... @iteration is div by ...", since the structure should already be given by the model.
But sure, you'll never be able to avoid "messy" templates completely. It simply comes with complexity. | Jacques1! I got Smarty working. I don't like it at all! Now I see how much I like the idea of using php tags within html code! Maybe I am just new to this! This is strange that everyone uses template engines. I know we talked about this but I still think the messy code is inevitable and the benefits are nothing compared to the headache. Or maybe I am missing the whole point.
PHP Code:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Members_model extends CI_Model
{
function list_members()
{
$query = $this->db->query("SELECT * FROM members");
return $query->result();
}
}
PHP Code:
public function list_members()
{
$this->load->model('members_model');
$members = $this->members_model->list_members();
$this->smarty->assign("members", $members);
$this->smarty->view('index');
}
Code:
{section name=co loop=$members}
{$members[co]->email}<br />
{/section}
Last edited by zxcvbnm : November 20th, 2012 at 04:56 AM.
|

November 20th, 2012, 04:57 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
Um, you've used Smarty for two days, and you've already come to the conclusion that template engines in general are bad?
First of all, you've picked the most cumbersome solution. Simply make a foreach:
Code:
{foreach $members as $member}
{$member->email}<br />
{/foreach}
Secondly, if you don't like Smarty, then simply try another engine. Wasn't that the whole point of this thread?
I mean, nobody forces you to use template engines. If you want to use the good old PHP tags, simply do it. But making a decision based on a quick look and "this looks strange" doesn't sound like a good idea.
|

November 20th, 2012, 05:33 PM
|
 |
Contributing User
|
|
Join Date: Aug 2011
Location: The Pleiades
|
|
To be honest, I'm using a template which I found from watching a couple of youtube videos. This guys setup works really really well with what I am doing. It's all about using one main index.php page to display all your HTML template pages. Such a neat system.
Check this out: http://www.youtube.com/user/betterphp
Browse through his videos and you will come across templates which he writes the code for in his videos. He explains things pretty well also.
Hope this helps.
Regards.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|