Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Basically, I think that template engines suck.
Goto page 1, 2, 3  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
marccho
Smarty Rookie


Joined: 02 Jan 2004
Posts: 12
Location: Barcelona/Catalonia

PostPosted: Fri Jan 02, 2004 6:03 pm    Post subject: Basically, I think that template engines suck. Reply with quote

Basically, I think that template engines suck. And smarty is not an exception to me.

I think that a lot of people are very confused because they don't realise that using a template engine IS NOT the only way to separate appearance from logic and IS NOT the only way to use templates.

I think that it's stupid to reparse what php already parses and to reinvent what php already is. And the most stupid think to me is that many template engines not only reinvent the language but what it's worse, by doing this they allow control structures inside the templates which I believe it's a complete contradiction: isn't the main purpose of template engines to separate appearance from logic? And aren't control structures THE logic?
Back to top
View user's profile Send private message
BRDude
Smarty Rookie


Joined: 23 Nov 2003
Posts: 17

PostPosted: Fri Jan 02, 2004 8:42 pm    Post subject: Reply with quote

marccho, please enlighten us, what are other more practical ways of separating appearance from logic? Seriously.

I came to like the idea of using templates and Smarty was the only engine which made things relatively easier for me.

Yes, I have complaints myself, reinventing the language like you said is one of them, it's like dealing with a whole other set of arbitrary rules. I wish it could be simpler.

The reparsing thing does seem like a lot of extra work, but Smarty's caching makes it worthwhile. Cached templates don't need reparsing.

About control structures, I believe Smarty's developers where trying to make things easier for us with additional features. You don't HAVE to use them, you can keep them all in the logic where they belong, but they're available in the template engine just in case.

Besides, there's this whole thing about making the templates editable by other people (webdesigners, clients, etc.) without having them constantly bother programmers about logic. I like that.

If you think about it, there's an arbitrary boundary between logic and appearance. It's up to programmers to define which is which. Smarty just happens to provide the tools you need to define them.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Jan 02, 2004 10:41 pm    Post subject: Reply with quote

This argument (and many like it) have been driven into the dirt many times over, no sense repeating it here. marchho, try putting a little bit of intellectual capacity to your statement next time intead of pure derrogatory BS, maybe someone will respect what you have to say.
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri Jan 02, 2004 11:54 pm    Post subject: Reply with quote

smarty is not about separating appearance from logic. it's about separating display-logic from business-logic.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
marccho
Smarty Rookie


Joined: 02 Jan 2004
Posts: 12
Location: Barcelona/Catalonia

PostPosted: Sat Jan 03, 2004 12:06 am    Post subject: Reply with quote

messju wrote:
smarty is not about separating appearance from logic. it's about separating display-logic from business-logic.


You mean separating logic from logic then? Simply use OO for instance. Anyway, this doesn't change much of what I said.
Back to top
View user's profile Send private message
marccho
Smarty Rookie


Joined: 02 Jan 2004
Posts: 12
Location: Barcelona/Catalonia

PostPosted: Sat Jan 03, 2004 12:40 am    Post subject: Reply with quote

BRDude wrote:
marccho, please enlighten us, what are other more practical ways of separating appearance from logic? Seriously.


Seriously, imagine you want to render a list of items, let's say some sort of articles like books in amazon for instance. But you want to apply the same appearance to all of the items. You can create two templates like the following:

list_articles.phtml:

Code:
<table border="0" cellspacing="2" cellpadding="2">
<?= $articles->render ( "single_article.phtml" ) ?>
</table>


single_article.phtml:

Code:
<tr>
<td><?= $this->get ( "name" ) ?></td>
<td><?= $this->get ( "date" ) ?></td>
<td><?= $this->get ( "price" ) ?></td>
</tr>


In this example, the render method of the class that manages a set of articles is where the rendering logic remains.

You can code very complicated rendering methods accepting many templates for applying in diferent cases. Here you have an example:

Code:
function render ( $template, $template_end = "" )
{
    global $path_template;
    global $lang;
   
    if ( empty ( $template_end ) ) $template_end = $template;

    for ( $this->i = 0; $this->i < $this->num_rows -  1; $this->i++ )
    {
        include ( $path_template.$template );
    }

    if ( $this->i < $this->num_rows ) include ( $path_template.$template_end );

}


where $path_template is the path to your templates and $lang a language array.

Of course, you can combine this tecnique with divs and you can apply any caching system to your templates.

I wrote my own template engine and realised how incredibly slow it can be. And I mean SLOW. Just because you are parsing the templates when it's completely unnecessary.

BTW, you can apply very similar tecniques to render an XML document. XSLT really sucks to me too. I have used it many times and I wasted my precious time.

Quote:
Making the simple complicated is common place . Making the complicated
simple, awesomely simple, that's creativity. Charles Mingus
Back to top
View user's profile Send private message
marccho
Smarty Rookie


Joined: 02 Jan 2004
Posts: 12
Location: Barcelona/Catalonia

PostPosted: Sat Jan 03, 2004 1:15 am    Post subject: Reply with quote

mohrt wrote:
This argument (and many like it) have been driven into the dirt many times over, no sense repeating it here. marchho, try putting a little bit of intellectual capacity to your statement next time intead of pure derrogatory BS, maybe someone will respect what you have to say.


It's strange, I speak Catalan, Spanish, English, French and Bulgarian, I can also understand Portuguese, Italian and Occitan but I really don't understand your language.

I'm sorry.
Back to top
View user's profile Send private message
BRDude
Smarty Rookie


Joined: 23 Nov 2003
Posts: 17

PostPosted: Sat Jan 03, 2004 5:35 pm    Post subject: Reply with quote

marccho, sounds interesting to use just PHP for the parsing. It's like you're saying that PHP is already equipped to do what Smarty wants to do.

I'd be willing to try out solutions that are simpler than template engines. One thing I really like about Smarty though, is that it provides a framework with important features like caching, plugins, security, config files, etc. already nicely OO-coded in. If I'm not using Smarty, I want a framework where I can easily separate logic from appearance (or display from business logic like messju put it) without worrying about details or reinventing the wheel (coding my own template solution).

Can you suggest an alternate framework that would make things simpler? You mentioned "caching with divs", no idea what that is, I'll have to look that up if I want to use caching without Smarty.

What about security? If templates are basically PHP files that only display or include other templates, what would stop the template designer (which could be a webdesigner, content editor or a store owner in a multi-user e-commerce system) from writing hazardous or stupid code? These templates would have to be parsed somehow to screen for that.

I like the idea, really, but I still think people want a framework to keep things organized and easier. Just come up with one and we'll see if it's better than using a template engine.
Back to top
View user's profile Send private message
BRDude
Smarty Rookie


Joined: 23 Nov 2003
Posts: 17

PostPosted: Sat Jan 03, 2004 5:44 pm    Post subject: Reply with quote

btw, when I said framework, I meant just a proper set of features related to doing something. I know ppl use the term "framework" mostly for higher level stuff.
Back to top
View user's profile Send private message
tk
Smarty Regular


Joined: 31 Oct 2003
Posts: 49
Location: London, UK

PostPosted: Sat Jan 03, 2004 8:13 pm    Post subject: Reply with quote

messju wrote:
smarty is not about separating appearance from logic. it's about separating display-logic from business-logic.


And IMHO.. with this mindset of how things work, (in a similar way I guess to the way I've started out using Smarty), with PHP being kept as PHP and Smarty used to help with the HTML side of the rendering, then Smarty (for me anyway) almost acts as an enhancement to HTML itself rather than PHP itself. The likes of a simple {if...}{/if} block is much easier for designers to understand and use.. and therefore gives _them_ more control over the actual rendering of the output.. rather than actually giving the programmer more control (although this can / does come into play with some scenarios).

A project I'm currently developing for a customer uses Smarty and they have self-admitted limited knowledge of PHP. Had I thrown the lot all together (like all my other sites are / were until recently) then unfortunately, they would have been pretty much at a loss as to any changes they wished to make to either the PHP _or_ HTML. Separating design and display logic in this sense helped immensely and the customer has been able to change the template file(s) to suit their own requirements / site design.. meaning that everyone is happy.. including me.. as I don't have to go back and repair some PHP they may have broken during modification.

My £0.02 worth anyway =)



Regards,

tk
_________________
Certified Code Junkie(tM)
Copyleft (L) two thousand and now, tk


Last edited by tk on Sat Jan 03, 2004 10:02 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Gerald
Smarty Regular


Joined: 26 Nov 2003
Posts: 53
Location: Lyon [France]

PostPosted: Sat Jan 03, 2004 9:08 pm    Post subject: Reply with quote

marccho wrote:
It's strange, I speak Catalan, Spanish, English, French and Bulgarian, I can also understand Portuguese, Italian and Occitan but I really don't understand your language.

That may be the reason why you can't understand template engines..... you can't handle anything more Smile
...Sorry for that... but I couldn't resist... (you've been rude to..... Wink)

Seriously... You're right, template engines are not the only way to separate business logic from display logic. You can do this directly in PHP, like you said.

BUT, Smarty IS a way to do so. And more than that, it may doesn't (actually I believe it doesn't) suck because of the followings:

- It's quicker to write {$variable} than <?php echo $variable; ?>

- It's even more quicker and more readable to have
{foreach from=$myTab item=someValue}
{$someValue}<br />
{/foreach}
than
<?php foreach ($myTab as $someValue) { ?>
<?php echo $someValue; ?><br />
<?php } ?>

- It's getting really interresting when you can use plugins that are only included while they are needed, without anymore attention
{calendar name=myDateInput}

you could of course do something like

<?php
include_once ('yourLibWithYourCalendar');
echo yourCalendarFunction ('yourDateInputName');
?>
But you have to mind your includes, and to write things that are already done in Smarty.

- You can apply modifiers to _all_ your variables (as html_escape to avoid cross scripting issues) by applying a default modifier in your smarty config file.

- You can enable / disable some functions in your templates. You can't really do so in PHP.

- People could go for the dark path in PHP, proceeding business logic in the "PHP template", it's not that easy using Smarty... it can be a "quick reminder" for others (not all the developpers are aware of the "template concept").

Anyway, you really can find lots of good things while using Smarty.
You can do the same things in PHP.... of course.
Smarty is still a good "framework" to do so.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sun Jan 04, 2004 7:10 pm    Post subject: Reply with quote

marccho wrote:


It's strange, I speak Catalan, Spanish, English, French and Bulgarian, I can also understand Portuguese, Italian and Occitan but I really don't understand your language.

I'm sorry.


It's your use of "that sucks" and "thats stupid" that sets the negative tone.

Anyways, it sounds like you came in here without investigation anything about Smarty, let alone using it. Read the "why use" section, that should point out some things about smarty other than just separating presentation.
Back to top
View user's profile Send private message Visit poster's website
marccho
Smarty Rookie


Joined: 02 Jan 2004
Posts: 12
Location: Barcelona/Catalonia

PostPosted: Mon Jan 05, 2004 10:26 am    Post subject: Reply with quote

Quote:
It's your use of "that sucks" and "thats stupid" that sets the negative tone.

Anyways, it sounds like you came in here without investigation anything about Smarty, let alone using it. Read the "why use" section, that should point out some things about smarty other than just separating presentation.


Yes, I know I use sexy words like "sucks" and "stupid" but please keep in mind that I give reasons. Not like others...

I don't like argumenting like "you have no idea", "read more books", "I serve 100 millions pages", etc...or even, I speak 5 languages.

I want you to know that I have programmed a template engine on my own and I realised that it's more a waste of time than anything else....It's my sincer contribution to the php programmers community. I find no pleasure in writting sexy words without arguments. If I just wanted to bother somebody I'd choose the asp or java comunity.
Back to top
View user's profile Send private message
marccho
Smarty Rookie


Joined: 02 Jan 2004
Posts: 12
Location: Barcelona/Catalonia

PostPosted: Mon Jan 05, 2004 10:36 am    Post subject: Reply with quote

Programmers code and designers design. If a designer sees a control structure be it smarty pseudo-code or php for me it's something invalid.

Using templates your friends can change much of the layout, the part that doesn't need coding. If they want to change the other part, this means they need a kind of programmer, be it a rendering-only programmer or a fully skilled programmer.

Using templates and rendering code as I suggest also makes it easier to maintain and reuse rendering code as it can be encapsulated in classes.
Back to top
View user's profile Send private message
marccho
Smarty Rookie


Joined: 02 Jan 2004
Posts: 12
Location: Barcelona/Catalonia

PostPosted: Mon Jan 05, 2004 11:18 am    Post subject: Reply with quote

Quote:
That may be the reason why you can't understand template engines..... you can't handle anything more Smile
...Sorry for that... but I couldn't resist... (you've been rude to..... Wink)


It could be.

Quote:
Seriously... You're right, template engines are not the only way to separate business logic from display logic. You can do this directly in PHP, like you said.


I apreciate your humbleness here indeed.

Quote:
- It's quicker to write {$variable} than <?php echo $variable; ?>


You can simply write <?= $variable ?>. Not a good start.

Quote:
- It's even more quicker and more readable to have
{foreach from=$myTab item=someValue}
{$someValue}<br />
{/foreach}
than
<?php foreach ($myTab as $someValue) { ?>
<?php echo $someValue; ?><br />
<?php } ?>


You didn't understand what I said: NO CONTROL STRUCTURES. Not a good follow-up.

Quote:

- It's getting really interresting when you can use plugins that are only included while they are needed, without anymore attention
{calendar name=myDateInput}

you could of course do something like

<?php
include_once ('yourLibWithYourCalendar');
echo yourCalendarFunction ('yourDateInputName');
?>
But you have to mind your includes, and to write things that are already done in Smarty.


Stop.

That and many other things will never be worth the time I'm losing when parcing twice and anyway I can do them without using smarty and hence without parcing twice.

The word "framework" is one of those words that microsoft uses to sell reinvented things. Pure hype. Just like the .NET bullshit.

Rage against microsoft's hype machine. Rage against wild capitalism!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP