SitePoint Sponsor |
|
User Tag List
Results 51 to 75 of 88
-
Jan 1, 2008, 22:37 #51
- Join Date
- Mar 2007
- Posts
- 196
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It actually would be more server load even though it would be minimal b/c when you use a template engine such as Smarty there is more parsing going on b/c it parses the new syntax into the real syntax thus adding another layer of parsing.
Kayzio - We don't hesitate, we accelerate.
-
Jan 1, 2008, 22:50 #52
-
Jan 1, 2008, 23:29 #53
- Join Date
- Mar 2007
- Posts
- 196
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yea but sometimes templates have dynamic content in them that periodically changes.
Kayzio - We don't hesitate, we accelerate.
-
Jan 2, 2008, 01:17 #54
- Join Date
- Jan 2001
- Location
- chennai , tamil nadu , India
- Posts
- 710
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
IT would be great if there is some way we can take a poll among the actual web designers which they would prefer php code or smarty tags ?
Chris, Programmer/Developer,
Laravel Php Developers, Ruby on Rails programmers,
Moodle, Opencart, Magento, Geodesic Classifieds/Auctions,
www.chrisranjana.com
-
Jan 2, 2008, 03:09 #55
-
Jan 2, 2008, 03:15 #56
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Jan 2, 2008, 04:09 #57
- Join Date
- Oct 2004
- Posts
- 88
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
server load
till now i couldn't find truth in any poll.
to come back to the higher server load argument. No, this is not a very good argument against smarty if its concept would have advantages. But as mentioned before, there are other, better, arguments to use php as template engine. We can pay good concepts with higher server load but this isnt an issue here.
-
Jan 2, 2008, 10:49 #58
- Join Date
- May 2007
- Posts
- 43
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Smarty parses it's template files turning them into .php with PHP syntax.
So if you have the following template
Code HTML4Strict:{foreach from=$mydata item=data} <tr> <td> {$data->id} </td> </tr> {/foreach}
It will run this once and parse the smarty code and make it something like this:
PHP Code:<?php $_from = $this->_tpl_vars['mydata']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
foreach ($_from as $this->_tpl_vars['data']):
?>
<tr>
<td>
<?php echo $this->_tpl_vars['data']->id; ?>
</td>
</tr>
<?php endforeach; endif; unset($_from); ?>Quality Shared and Reseller Web Hosting
Cpanel/WHM • RvSkins • Fantastico de Luxe • 24/7 Support
PHP5 • Zend Framework • PDO • Ruby On Rails • Subversion • Trac
Hawk Host Inc. Quality Web Hosting Since 2004
-
Jan 2, 2008, 15:11 #59
- Join Date
- Nov 2007
- Posts
- 13
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Actually all its use of caching tells you is that parsing templates is potentially expensive and as such it avoids doing it as much as possible.
The argument that template engines hurt performance and create bloated applications just doesn't hold water. Any sensibly designed templating engine is going to have near no overhead.
-
Jan 2, 2008, 15:55 #60
- Join Date
- Sep 2006
- Location
- Nottingham, UK
- Posts
- 3,133
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Given the sample code from the post before yours, the smarty code basically looks like PHP functionality, but rewritten to something different. Are you telling me that rewriting a language to achieve nothing at all (after all, the whole point is to separate the logic, and it actually just has exactly the same logic in a different format) isn't excess bloat?
That code example also puts to rest the 'designers cant use programming languages' argument. If they understand the concepts of one, all that you need for the other is a knowledge of the syntax.
-
Jan 2, 2008, 20:30 #61
- Join Date
- Mar 2007
- Posts
- 196
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have to definately agree with stormrider on this one.
Kayzio - We don't hesitate, we accelerate.
-
Jan 2, 2008, 23:15 #62
- Join Date
- May 2005
- Location
- India
- Posts
- 564
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Hi,
Smarty is burden for personal developers. If you're just a single developer and developing custom applications which you will sell to just 1 or 2 clients then according to me you should make your own arrangements so its easy for you in the longer run.
If you're a team for a big project or a business project in which the design will keep on changing and programmers/designers will keep on changing then use standard stuff like Smarty etc. so new people who come aboard can easily adapt the to the project and start giving output asap.
Its really just to save time and money. Its you who has to decide which way you have to do it - really. Oh personally i like phpbb's template engine atleast in that we don't have to learn another language. For eg. they do loops like this in template:
Code:<select name="somedd"> <!-- My Loop - Begins --> <option value="{value}">{display_name}</option> <!-- My Loop - Ends --> </select>
Thanks.
-
Jan 2, 2008, 23:33 #63
- Join Date
- Dec 2007
- Location
- Bed Room
- Posts
- 134
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OneSeventeen: i am new to smarty , gathering information on smarty, what was that link( to tutorial u read)
-
Jan 3, 2008, 08:27 #64
- Join Date
- Nov 2004
- Location
- Lincoln Nebraska
- Posts
- 1,161
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That example is actually rather complex and not something I would give our designer to work with. Smarty has a lot of language constructs that I don't find use for. Loops and if constructs are almost unavoidable, there is a lot of other functionality which isn't entirely necessary for templating. I occasionally will create complex data driven markup myself and feed it to a smarty variable rather than represent it in template language. It may break the rules somewhat, but I don't care.
We have to deal with a lot more rules than what a tag based system like Smarty imposes. Curly braces, function arguments, ending lines with semi-colons. Smarty has if and endif and similar simpler rules. If you were forced to do an application with just what Smarty provides, you would be pretty frustrated. It's simply not the same thing.
We are talking about PHP, but what about designers that come from ASP, Cold Fusion or Ruby shops. Are they expected to learn all those disciplines just so they can work with the back end people? On who's dime do they learn?
Don't let your perspective as a programmer make you think that everyone has the same aptitude in the same areas as you (a stock broker isn't stupid because he isn't computer literate although there is a limit to that concept), or forget what you or others may have gone through to develop the knowledge that you have.
-
Jan 3, 2008, 10:00 #65
-
Jan 3, 2008, 10:05 #66
- Join Date
- May 2005
- Location
- India
- Posts
- 564
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Hi,
We should dtop aruging on this topic it will never end.
Thanks.
-
Jan 3, 2008, 10:23 #67
-
Jan 3, 2008, 15:08 #68
Actually, you are achieving something. Compare the first lines:
Code:{foreach from=$mydata item=data} vs. <?php $_from = $this->_tpl_vars['mydata']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)): foreach ($_from as $this->_tpl_vars['data']): ?>
Code:{$data->id} vd <?php print $data->id ?>
-
Jan 3, 2008, 16:27 #69
- Join Date
- Dec 2003
- Location
- Albany, New York
- Posts
- 1,355
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That amount of PHP code is unnecessary. How about:
PHP Code:<?php if(empty($array)) { ?>
No thingies.
<?php } else { ?>
<?php foreach($array as $thingy) { ?>
<?php echo $thingy ?>
<?php } ?>
<?php } ?>
Use echo. It's shorter.
-
Jan 3, 2008, 17:20 #70
-
Jan 4, 2008, 00:44 #71
- Join Date
- Sep 2004
- Location
- Zagreb, Croatia
- Posts
- 830
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I write my PHP templates like this:
PHP Code:<?php if(empty($array)) : ?>
No thingies.
<?php else : ?>
<?php foreach($array as $thingy) : ?>
<p><?= $thingy ?></p>
<?php endforeach ?>
<?php endif ?>
-
Jan 4, 2008, 05:45 #72
- Join Date
- Nov 2007
- Posts
- 13
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The example you make reference to isn't a particularly good example of how to use a template engine.
In my mind the qualities of a good template engine are:
- No PHP allowed in templates for security and ensure consistency in their use.
- No silly braces to represent anything beyond simply echoing out a value.
- Use XML style tags embedded in the html which makes calls to a registered view helper class.
- Ensure that any remotely complex logic is stored in the helper.
Here's a brief example of how it'd look
HTML Code:<helper:authenticated> <p>You're logged in!</p> </helper:authenticated> <helper:notauthenticated> <p>You're not logged in!</p> </helper:notauthenticated>
Now, to answer those who I'm sure would question why you wouldn't just replace the above code with the following:
PHP Code:<?php if ($helper->authenticated()): ?>
<p>You're logged in!</p>
<?php endif; ?>
<?php if (!$helper->authenticated()): ?>
<p>You're not logged in!</p>
<?php endif; ?>
If the issues mentioned above are not problems for you, then a PHP based view may be all you need. However, if you do have concerns about security or consistency, then don't discount a template engine.
-
Jan 4, 2008, 12:57 #73
- Join Date
- May 2007
- Posts
- 28
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Template-engine discussions are neverending stories:
Template Engine or PHP/HTML-mixed-view usage? - well, as always, it depends!
When you have a middle/major sized project, with lots of people involved, a template-engine is the right way to go, fmpov. It will definitly safe you some time. Libraries like Smarty are stable, good documented and you can get lots of usage examples. Not said, that this would not be possible with going the html+php route, but.. when you rely on a library your options in the "view" are some kind of restricted to the expression-possibilites of the library itself. And on projects with many people involved, such standards are highly recommended.
You could say they do it all wrong - but, another fact is, that a big bunch of major web-applications are template-engine driven. Be it Smarty, Joomla's patTemplate or Drupal's phptal.
-
Jan 4, 2008, 13:27 #74
That was an extreme example, but my point is that even in the simplest cases, the syntax of a smarty or another templating engine will be shorter than the pure php version, which makes the template version easier to read. It is a trade off, though, and on small projects where I'm the sole developer I don't bother; but on big projects with multiple developers, a templating engine can make life easier.
-
Jan 6, 2008, 10:37 #75
- Join Date
- Dec 2003
- Location
- Albany, New York
- Posts
- 1,355
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What I often do is assign everything (or near everything) to a variable, much like in a templating system. But instead of assigning it to a member of a tpl_var array, I just throw it all in the global scope and include the template.
I'm sure tons of people are against the whole global concept, and I'm sure you could do things more elegantly, but I've found it to be the simplest, easiest method. It's also quite reminiscent of a template engine. Just with cooler syntax.
Originally Posted by BerislavLopac
Short doesn't necessarily mean easier to read. I personally find PHP easier to read than Smarty (perhaps because I'm more familiar with PHP). Regardless, I still think "foreach posts as post" is easier to read than "foreach from equals posts item equals post."
Bookmarks