SitePoint Sponsor

User Tag List

Page 3 of 4 FirstFirst 1234 LastLast
Results 51 to 75 of 88
  1. #51
    SitePoint Zealot
    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.

  2. #52
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kayzio View Post
    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.
    It parses the template once, and then all requests use the compiled version, only re-parsing if you change the template. The overhead is negligible; at the least, it isn't a valid reason not to use it.

  3. #53
    SitePoint Zealot
    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.

  4. #54
    Web development Company chrisranjana's Avatar
    Join Date
    Jan 2001
    Location
    chennai , tamil nadu , India
    Posts
    705
    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,
    www.chrisranjana.com

  5. #55
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kayzio View Post
    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.
    The fact that it needs caching in the first place to claw back some performance should tell you something about how much more bloated it makes your applications...

  6. #56
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chrisranjana View Post
    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 ?
    Such polls are rarely very useful. I'm pretty sure, you would get a number of votes for both solutions.

  7. #57
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    server load

    Quote Originally Posted by kyberfabrikken View Post
    Such polls are rarely very useful. I'm pretty sure, you would get a number of votes for both solutions.
    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.

  8. #58
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kayzio View Post
    Yea but sometimes templates have dynamic content in them that periodically changes.
    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

  9. #59
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    The fact that it needs caching in the first place to claw back some performance should tell you something about how much more bloated it makes your applications...
    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.

  10. #60
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Richard Bone View Post
    The argument that template engines hurt performance and create bloated applications just doesn't hold water.
    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.

  11. #61
    SitePoint Zealot
    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.

  12. #62
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    563
    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>
    The code between the html comments will be used for the loop. Now this is called simplicity. LOL

    Thanks.

  13. #63
    SitePoint Zealot impunjabians's Avatar
    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)

  14. #64
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    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.
    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.

  15. #65
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If they have a different programming language background, it is fairly easy to learn another language. Its a case of syntax, all languages have the same constructs really.

  16. #66
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    563
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    We should dtop aruging on this topic it will never end.

    Thanks.

  17. #67
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'm not arguing, I'm discussing :P

  18. #68
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    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?
    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']):
    ?>
    The smarty version is 1/4 of the size, and does some basic type checking you don't get if you simply did a foreach in PHP. Even the most trivial example:

    Code:
    {$data->id}
    
    vd
    
    <?php print $data->id ?>
    The smarty version is half the size, which might not seem like much, but on a big page it makes a real difference. And that, to me, is the basic problem with using pure php; the syntax is bloated, which leads to templates being hard to read and maintain, and using a template language can help with this tremendously.

  19. #69
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 33degrees View Post
    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']):
    ?>
    The smarty version is 1/4 of the size, and does some basic type checking you don't get if you simply did a foreach in PHP.
    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 
    ?>
    Which could of course be shortened if it was being programmed by a man with one finger. What would the equivalent be in Smarty?

    Quote Originally Posted by 33degrees View Post
    Code:
    {$data->id}
    
    vd
    
    <?php print $data->id ?>
    Use echo. It's shorter.

  20. #70
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by 33degrees View Post
    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']):
    ?>
    The smarty version is 1/4 of the size, and does some basic type checking you don't get if you simply did a foreach in PHP. Even the most trivial example:

    Code:
    {$data->id}
    
    vd
    
    <?php print $data->id ?>
    The smarty version is half the size, which might not seem like much, but on a big page it makes a real difference. And that, to me, is the basic problem with using pure php; the syntax is bloated, which leads to templates being hard to read and maintain, and using a template language can help with this tremendously.
    If you wrote the php template like that, then yes, it saves time. Luckily I don't. I have functions to check and validate data much earlier on (as im sure you do when using smarty as well), then just use a simple foreach loop.

  21. #71
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Young Twig View Post
    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 
    ?>
    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 ?>
    Quote Originally Posted by Young Twig View Post
    Use echo. It's shorter.
    <?= is even shorter. I know that it may not be universal, but it's quite good enough for my purposes. And if necessary it can be transformed to <?php echo with a simple search and replace.

  22. #72
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    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?
    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>
    Granted that's a very simplistic example, but hopefully it gives you an idea what I'm driving at.

    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; ?>
    The above example is actually pretty good code, and it's simple to understand by PHP developers. However, you wouldn't want to use the PHP method if you have concerns about security (this should be a concern where untrusted parties may have access to the templates), or if you want to ensure consistency so that some developer you hired two weeks ago doesn't stick an SQL query in the middle of your template.

    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.

  23. #73
    SitePoint Enthusiast
    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.

  24. #74
    SitePoint Guru 33degrees's Avatar
    Join Date
    May 2005
    Posts
    707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    If you wrote the php template like that, then yes, it saves time. Luckily I don't. I have functions to check and validate data much earlier on (as im sure you do when using smarty as well), then just use a simple foreach loop.
    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.

  25. #75
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Richard Bone View Post
    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>
    Granted that's a very simplistic example, but hopefully it gives you an idea what I'm driving at.

    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; ?>
    The above example is actually pretty good code, and it's simple to understand by PHP developers. However, you wouldn't want to use the PHP method if you have concerns about security (this should be a concern where untrusted parties may have access to the templates), or if you want to ensure consistency so that some developer you hired two weeks ago doesn't stick an SQL query in the middle of your template.

    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.
    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.

    Quote Originally Posted by BerislavLopac
    <?= is even shorter. I know that it may not be universal, but it's quite good enough for my purposes. And if necessary it can be transformed to <?php echo with a simple search and replace.
    Yeah, I know, but I've been brainwashed into the anti–short tags cause.

    Quote Originally Posted by 33degrees View Post
    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.
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •