
|
View Full Version : How many people use Smarty?
JustinSmall 09-28-2008, 11:40 AM I was just wondering how many people use Smarty — from WHT — and why they use it.
I have personally been using Smarty for a few years, mainly on very large customer projects, and very little on my own websites. I have just recently started to do them on my own websites.
Smarty is always a good idea on client projects, because not everyone is as php savvy as you. They can easily edit the template without screwing everything up! :)
TonyB 09-28-2008, 11:55 AM Used it quite a bit as the view component on a lot of projects. Since I've moved 100% to Zend Framework I've just been using Zend_View which is PHP based templates. The difference isn't as huge as some might assume for example:
{$var}
vs
<?= $this->var; ?>
Codebird 09-28-2008, 01:57 PM I have always been thinking what advantages do smarty give me over server side includes, I mean I have always looked at things and I see that it is costing more functions and more code than the server side includes while it is giving a bit of the same result? If somebody can lead me to the advantages of smarty I'll be so thankful...
sorry if somebody finds it a bad question or something, just searching for a good explanation
TonyB 09-28-2008, 02:21 PM I have always been thinking what advantages do smarty give me over server side includes, I mean I have always looked at things and I see that it is costing more functions and more code than the server side includes while it is giving a bit of the same result? If somebody can lead me to the advantages of smarty I'll be so thankful...
sorry if somebody finds it a bad question or something, just searching for a good explanation
Smarty turns it's smarty code into php files then executes them after that point unless the files change. It's almost like includes.
The advantages of smarty is the user does not necessarily need to know php. I argue that using a php templating system is no different than smarty. In my example the difference was minimal at best and if a designer could use the smarty they could use the PHP as well.
Codebird 09-28-2008, 02:32 PM thanks a lot for the answer, I was afraid not being on the safe side staying with only "ssi".
etogre 09-28-2008, 02:34 PM I agree with TonyB. There is hardly a difference between:
{section name=mysec loop=$users}
<tr>
<td>{$users[mysec].name}</td>
<td>{$users[mysec].phone}</td>
</tr>
{/section}
and
<?php foreach ($users as $user): ?>
<tr>
<td><?=$user['name']?></td>
<td><?=$user['phone']?></td>
</tr>
<?php endforeach; ?>
If anything, it is more difficult because you are forced to use the templating engines specific syntax, which in some cases is more confusing than just PHP code. Not only that, but in the case of Smarty you add a significant amount of time to your benchmarks, which wouldn't necessarily matter too much because PHP's interpreter is pretty fast, but on a large site you could see some detrimental effects.
That said, it's up to the customer (or yourself if it is your project), the route you will go. I've used Smarty in the past, and while I do not necessarily like it, I will continue to because it is the standard most agree to.
My case is based on the fact that using a template system isn't to seperate PHP code from HTML, but rather the business logic from the presentation logic. You can achieve the same result with or without a template system like Smarty.
digitaldesperad 09-28-2008, 03:29 PM i use smarty to protect my email adress Smarty is not the most efficient template engine out there, but it is fairly flexible and well-used :)...
linux-tech 09-28-2008, 03:39 PM Since I started playing with smarty a couple years ago, I haven't really looked back. It's incredibly easy to use, and I've found it personally to save a good bit of time when updating websites.
Xeentech 09-28-2008, 04:49 PM Like linux-tech, I worked with Smarty on a project soon after it's release and I haven't had call to change when starting any new projects. Recently I was worried that I wouldn't be able to do a particular part of a project (threaded forum/discussion.. infinite replies to replies, displayed in a proper threaded/indented manner.) in Smarty, I was able to recursively include a template file which worked out great
It's been a good solution for projects where there are PHP devs and HTML/Photoshopers (I can't draw to save my life).
Personally I use it to "separate concerns."
ThatScriptGuy 09-28-2008, 05:30 PM I use it when the client requests it - Usually because they've heard the name somewhere. But I'm with a couple of you guys in that Smarty actually adds development time to my projects because I have a hard time converting my PHP thoughts/functions/loops into Smarty code.
Pluswhich, 99% of people I do work for never actually touch the code of their website themselves. Instead, they call me back to make code or design changes - NOT using Smarty makes my projects much easier, but perhaps that's just me.
JustinSmall 09-28-2008, 05:58 PM I for one am very high on 'clean and manageable' coding and design.
Smarty is used to separate code from design, and does a very good job of it. It offers a back-end (coding) and a front-end (design) that people often like to see.
While personal websites don't usually have it, larger sites should… such as blog/cms/ect software, because people do have templates for these softwares.
When a user doesn't really know how php works, they look at
<?php
//code
?>
and go, "crap, it's PHP"…
but when they look at
{username}
They go, "oh that means username"…
(Rough example I know)
---------------------------------------------
The thing is, the people that are developing these templates don't care to throw in all of these php codes, they just know that {whatever} will do whatever, making it very easy for them to create a template…
So my suggestion:
Personal Site - Sure, for quick and easy template updates
Large Commercial Software - Even if it's not Smarty, a Template Engine is a MUST!
ThatScriptGuy 09-28-2008, 06:11 PM Smarty adds a layer of complexity to my projects that I just don't need, even on my year-long projects. Someone looking at the .tpl files who doesn't know much about coding will think the same thing about Smarty or PHP when they see:
{section name=mysec loop=$users}
<tr>
<td>{$users[mysec].name}</td>
<td>{$users[mysec].phone}</td>
</tr>
{/section}
and
<?php foreach ($users as $user): ?>
<tr>
<td><?=$user['name']?></td>
<td><?=$user['phone']?></td>
</tr>
<?php endforeach; ?>
An uneducated user won't know what either of the blocks of code means, so why make MY job more difficult? It is COMPLETELY possible to create clean, maintainable, expandable code without using an unneeded system like Smarty to get in your way. In the hands of an uneducated user, a website will throw errors, just like PHP will.
I guess it just comes down to personal preference. I just can't bother with using Smarty unless a client absolutely demands it. I would much rather use a simplified template class (Which I do on 99% of my projects).
JustinSmall 09-28-2008, 06:33 PM Yeah, it's whatever works for you :)
The topic was specified as 'How many people use Smarty' btw ;)
but in defense of the programming!!!
9 out of 10 users who build templates understand HTML :) Now 2 or 3 out of those 9 who do understand it don't know PHP :)
linux-tech 09-28-2008, 06:38 PM 9 out of 10 users who build templates understand HTML :) Now 2 or 3 out of those 9 who do understand it don't know PHP :)
Prove it.. Show proof or don't just throw random meaningless numbers out there.
Statistically speaking, I'd say the 2 or 3 users would be more like 6 or 7, however, that is going off of my own personal experience. Or I could say that 9/9 don't know it. You can NOT throw numbers out there without backing up those numbers with proof.
The majority of people that know html don't know php. Why? html isn't hard to learn, it's very straight forward, and it's NOT a programming language. PHP can be complicated to learn, and IS a programming language
etogre 09-28-2008, 07:17 PM What we're saying, in the purest of forms, is that Smarty is in itself a programming language. Albeit maybe a simplified one, but after all it does have looping and branching structures. I don't know who made the rule that separating presentation from business logic meant we shouldn't use PHP code in view files, but it is not a valid one. Business logic is processing and manipulating the data, presentation is displaying it. Both can be done validly with PHP.
linux-tech 09-28-2008, 07:21 PM Smarty is in itself a programming language
No it's not. That's worse than saying html is a programming language, because at least html IS it's own language
Smarty is a template engine, not a programming language.
Without php, smarty would be nothing.
Smarty handles variables, has special functions to do special things , but is NOT a separate programming language.
etogre 09-28-2008, 08:18 PM I referred to it as being like a programming language because it has looping and branching structures, among other things, and a specific syntax. Sorry if I wasn't clear about that.
TonyB 09-28-2008, 10:04 PM PHP can be just a templating language and some sites use it for just that.
Smarty:
{$variable}
PHP:
<?= $variable; ?>
So you replace { on the smarty side with <?= and replace } on smarty with ?> and you get yourself PHP templating.
Now where some confusion may come in is the looping which needs a <?php instead. Not a huge difference.
So smarty when using just variables might not be much of a programming language. No one just uses it for strictly placing variables inside html. They use it for some logic as well.
For example here's some smarty syntax:
{foreach from=$myArray item=foo}
<li>{$foo}</li>
{/foreach}
PHP version:
<?php foreach($myArray as $foo): ?>
<li><?= $foo; ?></li>
<?php endforeach; ?>
The other big one you see a lot is if statements. But it can also do a slew of other things which to me makes it feel like a programming language:
{foreach},{foreachelse}
{if},{elseif},{else}
{include}
{include_php}
{insert}
{ldelim},{rdelim}
{literal}
{php}
{section},{sectionelse}
{strip}
Branching, looping, execution of php code
{assign}
{counter}
{cycle}
{debug}
{eval}
{fetch}
{html_checkboxes}
{html_image}
{html_options}
{html_radios}
{html_select_date}
{html_select_time}
{html_table}
{mailto}
{math}
{popup}
{popup_init}
{textformat}
There is one for assigning variables and another for doing math.
JustinSmall 09-29-2008, 09:23 AM I think we are a bit off topic (I am the topic starter,) I just wanted to know how many people use Smarty. I do care if you don't use it, and I do care if you do.
All I expected to hear was one of the two:
1) I use Smarty, it has helped me out greatly!
2) I don't use Smarty, I don't feel a need for it.
They aren't limited to those, but something similar!!!
No Smarty is not a programming language, it is an Engine built off of PHP… it uses it's variables based off PHP variables… but that truly doesn't matter as it isn't revelant to my initial question: 'How many people use Smarty?'
So from now on, please just say I use smarty, or I don't, and you can give an explanation if you'd like (but keep it short please!)
linux-tech 09-29-2008, 09:37 AM You posted a topic inside of a public forum, you don't get to tell people how to respond too. That's just silly. If you don't want discussion of 'smarty' and it's uses, don't create a thread about using smarty on a public forum!
Discussion of smarty is quite valid and 'on topic' in the thread itself.
So you replace { on the smarty side with <?= and replace } on smarty with ?> and you get yourself PHP templating.
It's just not that simple, actually.
With Smarty, you don't even worry about the php code (though loops, variables, et all are going to come into play). With php, you have to worry about messing around with things inside the php file itself.
With smarty, the code logic is effectively separated from the design logic, which is how it should be. MOST html designers don't know php, and will screw up a php file in one way or another. Alternatively, give them certain 'variables' to use, and MOST html designers will be fine using those instead.
No one just uses it for strictly placing variables inside html. They use it for some logic as well.
Incorrect . Before you say 'No one', you'd better make extremely sure that you KNOW everyone and KNOW what everyone is saying and doing, and using this for. In this case you don't, because, in this specific case I'm "No one".
In two years of dealing with smarty, I've found it easier to assign the variables through the code, and let the template system itself do what it's supposed to do, display the data. Now, that's with me doing simple stuff in smarty, but still, the idea for smarty is to handle the TEMPLATE side of things, not perform massive loops and structures.
JustinSmall 09-29-2008, 09:57 AM While I believe the topic is 'How many people use Smarty?' and not 'Smarty Template Engine' or 'Why do you use or not use Smarty'… then I believe arguing about it is off topic.
All I wanted to know was how many people use Smarty not an argument over Smarty!
TonyB 09-29-2008, 10:18 AM When I refer to PHP it's as if people assume all the business logic and the presentation logic are in the same file. Every PHP templating system I've used has separated them out into different files.
Very crude example:
index.php:
require_once("MyTemplateSystem.php");
$tpl = new MyTemplateSystem();
$tpl->assign('user',$_POST['user']);
$tpl->display('index.phtml');
index.phtml
My user is <?= $this->user; ?>
The designer is not messing around with the PHP files at all. You could tell them they're playing with phtml files which means presentation html.
Now semi to do with the topic at hand. I think the number of smarty users is going down and will continue to go down. The reason being PHP frameworks are using PHP based templating. You may use smarty but there are many disadvantages as helper classes will not exist for the smarty system.
luke_a 10-03-2008, 02:59 PM Smarty is useful for far more than variable replacement, and using short tags is discouraged as they can be disabled so your application may not work on some hosts.
etogre 10-03-2008, 04:37 PM You can easily rewrite short tags, and in fact most php frameworks do.
<?php
str_replace('<?=', '<?php echo ', $this->template);
?>
Have worked at multiple places using Smarty. Did see a need for it or something like it. Did work well for what it was.
Bandit-X 10-08-2008, 09:59 AM i use smarty. makes it really easy changing templates.
|