That's what SMARTY were designed for...



  • I've been recently fixing a cms written in PHP using SMARTY tpl's... well, it was one of the requirments to do so. I fixed few bugs, and started checking for optimization, and I've found that page template looks like these:

    {$page_text}

     The whole content was generated using PHP, and SMARTY... well, they wanted them, so here they are, with their whole functionality ;)



  •  TRWTF is Smarty.  Why do we need a template language for PHP which is itself a template language?  Fuck it.


  • Garbage Person

    @morbiuswilters said:

     TRWTF is Smarty.  Why do we need a template language for PHP which is itself a template language?  Fuck it.

     

     Because useless wanker web devs can't figure out how to not break PHP.



  • @Weng said:

     Because useless wanker web devs can't figure out how to not break PHP.



    And how do you "break" PHP? If you acctually meant breaking the application then i'm afraid smarty isn't going to help you.



  • @stratos said:

    @Weng said:
     Because useless wanker web devs can't figure out how to not break PHP.
    And how do you "break" PHP? If you actually meant breaking the application then i'm afraid smarty isn't going to help you.
     

    Maybe he means graphics designers? In my personal experience the vast majority of their expertise lies in using Dreamweaver and the like. Asking them to add their HTML to the PHP framework is usually like giving a 7 year old gunpowder and telling him to build his own fireworks. Even if he can figure it out, it will most likely end in tears.

    Unfortunately I have yet to meet a graphics designer that's interested in learning to use a template system, Smarty or otherwise. Their philosophy is usually "If I can't drag-n-drop, I aint using it".

    As for the OP... I hope they don't ask you to update the HTML.



  • My philosophy is "if you can't do html and css by hand, I am not working with you".



  •  Slightly side-tracking a bit, you just reminded me of the time I got called out- to remove a smarty from a USB socket. It's amazing what you find in there sometimes. I was so gobsmacked (This was an adult shop) that I took a picture- I'll have to go find it!



  • @DOA said:

    Maybe he means graphics designers? In my personal experience the vast majority of their expertise lies in using Dreamweaver and the like. Asking them to add their HTML to the PHP framework is usually like giving a 7 year old gunpowder and telling him to build his own fireworks. Even if he can figure it out, it will most likely end in tears.

    Unfortunately I have yet to meet a graphics designer that's interested in learning to use a template system, Smarty or otherwise. Their philosophy is usually "If I can't drag-n-drop, I aint using it".

    The one who should be electroshocked here is the person who asks a graphic designer to do any development at all. They are graphic designers. Not developers. A graphic designer -by definition- cannot do development, and a software developer cannot do graphic design. That's the whole point of specialization. It is just unfair to expect people to do stuff they are not trained to or don't have the affinity to do. Personally, I never will be able to sell cars, neither to catch criminals, nor to design graphics. That's because software development is my profession and I suck at everything else, including Photoshop, Dreamweaver and the rest.

    To be honest, I am sick of the arrogant elitist mentality of "everybody else is stupid" in the IT/Software Development Industry. It is really unprofessional and should be grown out already.



  • @DrJokepu said:

    To be honest, I am sick of the arrogant elitist mentality of "everybody else is stupid" in the IT/Software Development Industry. It is really unprofessional and should be grown out already.
    Yeah. But the question then remains... I got these fancy graphics here, and this nicely stable website that works great. Who is going to put them in the same jar and stir till it's one?



    The "I do software development, nothing else" mentality is also stupid. Someone has to put it all together. I've been a solo coder in a UT2004 mod (as hobby project), and while we had a few graphic artists, some modelers and a few people that build maps. I was the one that had to put it all together, rescaling models, fixing animations, exporting files to the right formats, fixing up maps, and tieing it all together in a final installer. In the end I had a 3D Studio Max, Photoshop and UnrealEd open, next to my coding tools (a text editor). Unless someone is getting out of that little box, you'll never get anywhere. Of course I'll never become a real artist, but I surely know the tools of the rest of the team.



  • @DrJokepu said:

    The one who should be electroshocked here is the person who asks a graphic designer to do any development at all. They are graphic designers. Not developers. A graphic designer -by definition- cannot do development, and a software developer cannot do graphic design. That's the whole point of specialization. It is just unfair to expect people to do stuff they are not trained to or don't have the affinity to do.
    Sounds good in theory, but in a project where a developer builds the code and the graphics designer does the HTML/CSS someone had to do the integration at the end. And when the graphics change and the graphics designer produces a new batch of HTML/CSS someone has to do it all over again. In practice it's the developer that has to do this mind-numbing grunt work. Which is why people have come up with template systems like Smarty.  And let's face it, using the HTML side of Smarty is not exactly rocket science. We're not asking graphics designers to track down a memory leak here.

    Even if it were unfair to ask graphics designers to use a template system, it's definately not as unfair as having a developer do cut-and-paste HTML grunt work. I don't see why both parties can't agree to use a template system and meet in the middle. 



  • Speaking of graphic designers, the one who works for my company had a real hard time learning PHP, and by learning, I mean learning about includes. She still often creates header.inc files (which can typically just be opened like text files across the web) and tons of other files. It's still an improvement when she first started working for me and was putting ASP in all of the files. I forgive all of this because she makes wonderful designs and templates.



  • urmmm, like someone already said. smarty is a tempalte language, and HEY what do you know, PHP is also a template language.

    <? FOREACH ( $items as $item): ?>

    <? IF ($item['special'] == true): ?>  special <? ENDIF; ?>

    <? ENDFOREACH; ?>

    vs.

    {foreach from=$items item=item}

    {if ($item.special == true) }  special {/if}

    {/foreach}

     

    No really what a big difference.



  • @stratos said:

    urmmm, like someone already said. smarty is a tempalte language, and HEY what do you know, PHP is also a template language.
    I don't understand. Do we have something better than Smarty and like for the separation of PHP from HTML/CSS in a way that can be maintained without the developer having to muck about with HTML/CSS?



  •  Dear Sir,

    I have be the requirement to write a Web 2.0 website in AJAX, SMARTY, PHP and CSV. SNARTY  says

    Smarty error: problem creating directory "templates_c/239/239105369"

    Smarty error: problem creating directory "templates_c/239/239105369"

    Smarty error: problem creating directory "templates_c/239/239105369"

    Could you tell me what the problem is? Please send me your code to hkhan@yahoo.co.in



  • @DOA said:

    I don't understand. Do we have something better than Smarty and like for the separation of PHP from HTML/CSS in a way that can be maintained without the developer having to muck about with HTML/CSS?

    Just use PHP.  Seriously, Smarty is just a slightly modified and weaker PHP syntax.  Your templates should mostly be HTML, CSS and JS anyway, with some variables pulled in and maybe a little bit of conditional logic or looping.  This is what Smarty does.  This is also what PHP does.  Why would you install a separate application to essentially emulate PHP-lite on top of PHP?



  •  @morbiuswilters said:

    Just use PHP.  Seriously, Smarty is just a slightly modified and weaker PHP syntax.  Your templates should mostly be HTML, CSS and JS anyway, with some variables pulled in and maybe a little bit of conditional logic or looping.  This is what Smarty does.  This is also what PHP does.  Why would you install a separate application to essentially emulate PHP-lite on top of PHP?
    Ah, I see. Well, assuming we have a graphics designer that would add his own stuff, I'd have to go with a template system because of the greater separation of presentation from code. Template systems tend to keep presentation in separate files which is good for graphics designers whose eyes understandably glaze over when confronted with the usual spaghetti of code and presentation you'd find a single PHP file (we're talking heavy-duty admin pages and the like here). Not only that but the more you have to deal with internationalization the more handy a template system becomes.

    That said, if I could find a graphics designer that's unfazed by the prospect of manouvering through code to make his changes (and can do so without messing up the code) I'd be more than happy to forego the template system and let him have a go at the .php files.



  •  Ummm, so you need a third party application to put your presentation code into another file?



  • @DOA said:

    Ah, I see. Well, assuming we have a graphics designer that would add his own stuff, I'd have to go with a template system because of the greater separation of presentation from code. Template systems tend to keep presentation in separate files which is good for graphics designers whose eyes understandably glaze over when confronted with the usual spaghetti of code and presentation you'd find a single PHP file (we're talking heavy-duty admin pages and the like here). Not only that but the more you have to deal with internationalization the more handy a template system becomes.

    That said, if I could find a graphics designer that's unfazed by the prospect of manouvering through code to make his changes (and can do so without messing up the code) I'd be more than happy to forego the template system and let him have a go at the .php files.

    Seriously, what the hell are you talking about?  PHP is a templating language, in addition to many other things.  If your pages are spaghetti logic all crammed into one file, that is your fault.  Ideally you would have PHP template files with well-constructed business objects kept completely separate.  There is no need for Smarty to accomplish this.



  • @morbiuswilters said:

    Ideally you would have PHP template files with well-constructed business objects kept completely separate. There is no need for Smarty to accomplish this.
    If like you said I'm going to have a separation of logic and presentation then someone has to build that architecture. Why would I opt for the not-invented-here option by building my own when an existing template system like Smarty can do it for me?



  • @DOA said:

    Why would I opt for the not-invented-here option by building my own when an existing template system like Smarty can do it for me?

    Why would I opt for the not-invented-here option by building my own when an existing template system like PHP can do it for me?



  • @DOA said:

    If like you said I'm going to have a separation of logic and presentation then someone has to build that architecture.
    Right, the PHP developers.
    @DOA said:
    Why would I opt for the not-invented-here option by building my own when an existing template system like Smarty can do it for me?
    WTF? Do you think Smarty is going to write your web app for you?



  • @DOA said:

    @morbiuswilters said:

    Ideally you would have PHP template files with well-constructed business objects kept completely separate. There is no need for Smarty to accomplish this.
    If like you said I'm going to have a separation of logic and presentation then someone has to build that architecture. Why would I opt for the not-invented-here option by building my own when an existing template system like Smarty can do it for me?

     

    If you want a framework, use a framework. There are plenty to choose from. Some use smarty, some don't. 

    But using smarty because its "easier for designers" is just bullshit.


  • @bstorer said:

    @DOA said:
    If like you said I'm going to have a separation of logic and presentation then someone has to build that architecture.
    Right, the PHP developers.
    Only a complete novice would write from scratch something he can get from a proven existing library. Try and educate yourself on good programming practices.@bstorer said:
    @DOA said:
    Why would I opt for the not-invented-here option by building my own when an existing template system like Smarty can do it for me?
    WTF? Do you think Smarty is going to write your web app for you?
    Are you on drugs? Which part of using Smarty for a webpage's templating needs didn't you understand?

    @stratos said:

    But using smarty because its "easier for designers" is just bullshit.
    It's easy to brand someone's suggestion as "bullshit" without offering an alternative. How do you think it should be done to be easier for designers?



  • @DOA said:

    @stratos said:
    But using smarty because its "easier for designers" is just bullshit.
    It's easy to brand someone's suggestion as "bullshit" without offering an alternative. How do you think it should be done to be easier for designers?
     

    @stratos said:

    urmmm, like someone already said. smarty is a template language, and HEY what do you know, PHP is also a template language.

    <? FOREACH ( $items as $item): ?>

    <? IF ($item['special'] == true): ?>  special <? ENDIF; ?>

    <? ENDFOREACH; ?>

    vs.

    {foreach from=$items item=item}

    {if ($item.special == true) }  special {/if}

    {/foreach}

     

    No really what a big difference.


     



  • @stratos said:

    urmmm, like someone already said. smarty is a template language, and HEY what do you know, PHP is also a template language.

    <snip>

    No really what a big difference.

    I don't understand. Your solution is using PHP code instead of the tags of a template system? How does that make a difference to a graphics designer?



  •  Ok this thread is starting to be a little bit redundant, so here is what my current company does. Although my company doesn't do PHP (we're an ASP.NET shop) we face similar problems. Our solution is that the HTML/webdesign/graphic design wizards do the HTML and then the developers wire it up with aspx functionality. Here is the rationale behind that: the "wiring up" part can be quite complicated in some cases, so that's something that should be done by a developer, no matter how boring or tedious the task is.



  • @DOA said:

    Only a complete novice would write from scratch something he can get from a proven existing library. Try and educate yourself on good programming practices.
    I'm quite aware of good programming practices. Perhaps you should avail yourself of some basic good practices, regardless of the field. Why the fuck would you suggest adding a template language to... A TEMPLATE LANGUAGE.
    @DOA said:
    Are you on drugs? Which part of using Smarty for a webpage's templating needs didn't you understand?
    I must be on drugs, because that's the only explanation for why I'm still trying to get it through your thick skull that PHP already does templating. What killer feature does Smarty offer that isn't already simple to template in stand-alone PHP?



  • @DOA said:

    @stratos said:

    urmmm, like someone already said. smarty is a template language, and HEY what do you know, PHP is also a template language.

    <snip>

    No really what a big difference.

    I don't understand. Your solution is using PHP code instead of the tags of a template system? How does that make a difference to a graphics designer?

    Exactly. It's just as easy, and doesn't require piling on an extra framework.



  • @bstorer said:

    Exactly. It's just as easy, and doesn't require piling on an extra framework.
    You think that because you clearly have never tried to separate content from logic in anything more complicated than a PHP form. Not to mention how laughable such a claim is if you have to deal with internationalization and localization.



  • @bstorer said:

    I'm quite aware of good programming practices. Perhaps you should avail yourself of some basic good practices, regardless of the field. Why the fuck would you suggest adding a template language to... A TEMPLATE LANGUAGE.I must be on drugs, because that's the only explanation for why I'm still trying to get it through your thick skull that PHP already does templating. What killer feature does Smarty offer that isn't already simple to template in stand-alone PHP?
     PHP is a programming language. Smarty is a template engine. Please tell me that you understand the difference.@bstorer said:
    What killer feature does Smarty offer that isn't already simple to template in stand-alone PHP?
    Are you serious? You've never used a template engine with PHP, have you?



  • @DOA said:

    @bstorer said:

    Exactly. It's just as easy, and doesn't require piling on an extra framework.
    You think that because you clearly have never tried to separate content from logic in anything more complicated than a PHP form. Not to mention how laughable such a claim is if you have to deal with internationalization and localization.

    This is absurd.  Smarty is no easier for people to work with than templated PHP.  You don't need any "magic" to use PHP as you would smarty, it's just good practice.  Your logic and your display should be separate.  Smarty does nothing to make this easier than PHP already does.  If you can't seem to write an app without churning out all-in-one-script PHP spaghetti code the solution isn't to use Smarty, it's for you to learn how to program properly before you propagate any additional WTFs.



  • @DOA said:

    @bstorer said:

    Exactly. It's just as easy, and doesn't require piling on an extra framework.
    You think that because you clearly have never tried to separate content from logic in anything more complicated than a PHP form. Not to mention how laughable such a claim is if you have to deal with internationalization and localization.

     

    Oh please great DOA, enlighten us how smarty does a better job at internationalisation. 

     



  • @DOA said:

    @bstorer said:

    Exactly. It's just as easy, and doesn't require piling on an extra framework.
    You think that because you clearly have never tried to separate content from logic in anything more complicated than a PHP form. Not to mention how laughable such a claim is if you have to deal with internationalization and localization.

    Just because you can't figure out how to write a PHP page with proper separation of business logic from display logic doesn't mean that good developers can't. I'd take a moment to reassess my abilities if I were you.



  • @morbiuswilters said:

    Smarty is no easier for people to work with than templated PHP.  You don't need any "magic" to use PHP as you would smarty, it's just good practice.  Your logic and your display should be separate.  Smarty does nothing to make this easier than PHP already does.  If you can't seem to write an app without churning out all-in-one-script PHP spaghetti code the solution isn't to use Smarty, it's for you to learn how to program properly before you propagate any additional WTFs.
    I don't understand why everyone's comparing PHP with Smarty. One's a programming language, the other a template engine.

    FACT: For anything above kindergarten level you can't get away with "<php code><my human readable text here><php code>". It. Just. Doesn't. Work. To find out why you need only try it out for yourself.

    So you need some sort of template engine. Which leaves us with rolling your own (see not invented here syndrome) or use an existing one.

    @stratos said:

    Oh please great DOA, enlighten us how smarty does a better job at internationalisation.
    You need only use a template engine for yourself.

    @bstorer said:

    Just because you can't figure out how to write a PHP page with proper separation of business logic from display logic doesn't mean that good developers can't. I'd take a moment to reassess my abilities if I were you.
    That's funny coming from someone who can't even tell the difference between a language and a template engine.



  • @DOA said:

    FACT: For anything above kindergarten level you can't get away with "<php code><my human readable text here><php code>". It. Just. Doesn't. Work. To find out why you need only try it out for yourself.
    Again, your actual business logic should not be mixed with HTML. This is extremely basic. That little bit of logic you do need for, say, building tables and stuff? You can write this easily in just PHP. Why don't you understand this?
    @DOA said:
    @bstorer said:
    Just because you can't figure out how to write a PHP page with proper
    separation of business logic from display logic doesn't mean that good
    developers can't. I'd take a moment to reassess my abilities if I were
    you.
    That's funny coming from someone who can't even tell the difference between a language and a template engine.
    I'm starting to get concerned that you don't understand the difference. I'll ask again: what do you expect to accomplish with Smarty that can't be done just as easily with PHP-sans-Smarty?



  • @DOA said:

    I don't understand why everyone's comparing PHP with Smarty. One's a programming language, the other a template engine.

    Holy fuck you're stupid.  PHP HAS TEMPLATING BUILT INTO THE LANGUAGE.  IT IS A CORE FEATURE.

     

    @DOA said:

    FACT: For anything above kindergarten level you can't get away with "<php code><my human readable text here><php code>". It. Just. Doesn't. Work. To find out why you need only try it out for yourself.

    I assure you I know a fuck of a lot more about PHP than you do.  All my logic is written in PHP and is composed of various business objects.  All of my templates are in their own files and essentially look like "<php code><html><php code>".  This is all you need.  The business logic handles construct all of the data and the PHP TEMPLATE FILES just echo variables, handle a light bit of conditional work (if($show_button), etc..) and  some light looping (like looping over an array of accounts, for example).  It's all very simple and looks dramatically different than my BUSINESS LOGIC WHICH IS WRITTEN IN PHP BUT IS NOT IN THE FUCKING TEMPLATE FILES.  Are you getting it yet?  Anyone with minor HTML and CSS experience can quickly learn how to edit the templates.  I HAVE NO NEED FOR SMARTY BECAUSE PHP ALREADY HAS TEMPLATING AS A CORE-FUCKING-FEATURE.



  • @morbiuswilters said:



    some good stuff.



    BUT WAIT!, theres more. It's amazing. The guys from php even went as far as to create a variant syntax for php that's more easier understood. specifically for use in templates.

    So instead of having to write <? echo $title; ?>  you can now write <?=$title;?> isn't it amazing!

    But wait, it gets even better. As to not confuse your designers with those weird curly brackets, they added alternative variants, so now you can just

    <? IF ($first_post): ?>

    <? ENDIF; ?>



  • @stratos said:

    BUT WAIT!, theres more. It's amazing. The guys from php even went as far as to create a variant syntax for php that's more easier understood. specifically for use in templates.

    So instead of having to write <? echo $title; ?>  you can now write <?=$title;?> isn't it amazing!

    But wait, it gets even better. As to not confuse your designers with those weird curly brackets, they added alternative variants, so now you can just

    <? IF ($first_post): ?>

    <? ENDIF; ?>
    Well, sure. But what about internationalization? Did you know that in some languages, "endif" isn't even a word?!



  •  @bstorer said:

    @stratos said:
    BUT WAIT!, theres more. It's amazing. The guys from php even went as far as to create a variant syntax for php that's more easier understood. specifically for use in templates.

    So instead of having to write <? echo $title; ?>  you can now write <?=$title;?> isn't it amazing!

    But wait, it gets even better. As to not confuse your designers with those weird curly brackets, they added alternative variants, so now you can just

    <? IF ($first_post): ?>

    <? ENDIF; ?>
    Well, sure. But what about internationalization? Did you know that in some languages, "endif" isn't even a word?!

    If my biggest concern with designers would be that i would have to explain them what the funny words between the php tags are, then i would be a happy man.



  • @morbiuswilters said:

    <rant>
    Ok, don't have an aneurism. I take it you've actually tried a template engine like Smarty and it turned out to be worse than your own stuff then? And of course you had to add other languages to your pages which <php code><html><php code> handled beautifully?

     @stratos said:

    <spouting script-kiddie-level nonsense>
    Yeah,good luck with that.

     @bstorer said:

    <funny, funny comment>
    Yup, nothing proves your point like aimless inanity.

     



  • @DOA said:

    @stratos said:
    <spouting script-kiddie-level nonsense>
    Yeah,good luck with that.
     

    thanks.

    I wondered when you would come to your senses. Apparently you just needed a good example.



  • @DOA said:

    I take it you've actually tried a template engine like Smarty and it turned out to be worse than your own stuff then?

    For the sake of fuck, I DON'T HAVE ANY OF MY OWN STUFF.  I use PHP which itself has templating built in.  I don't need to use Smarty.

     

    @DOA said:

    And of course you had to add other languages to your pages which <php code><html><php code> handled beautifully?

    It's handled as well as it is in Smarty, because Smarty is essentially just PHP templating written on top of PHP.  There is nothing Smarty does that PHP doesn't do.  Stop with this ridiculous bullshit.  You've already been sk00l3d by almost everyone here.



  • @DOA said:

     @bstorer said:
    <funny, funny comment>
    Yup, nothing proves your point like aimless inanity.
    It works better than your present strategy of continuous denial mixed with stupidity on a level that should preclude you from even using the internet to begin with.



  • @morbiuswilters said:

    @DOA said:
    I take it you've actually tried a template engine like Smarty and it turned out to be worse than your own stuff then?
    For the sake of fuck, I DON'T HAVE ANY OF MY OWN STUFF.  I use PHP which itself has templating built in.  I don't need to use Smarty.
    So that's a no. Never actually used a 3rd party template engine, but you know for a fact your code is better. Alrighty then.

    @bstorer said:

    @DOA said:
     [quote user="bstorer"]<funny, funny comment>
    Yup, nothing proves your point like aimless inanity.
    It works better than your present strategy of continuous denial mixed with stupidity on a level that should preclude you from even using the internet to begin with.[/quote] Yup, nothing proves your point like insults. At least mobius has some sort of argument to make, crippled as it is.



  • @DOA said:

    PHP is a programming language. Smarty is a template engine. Please tell me that you understand the difference.

    PHP is a templating language. Over time, it has grown to become a Turing-complete, feature-rich programming language (templating languages tend to do so). Because of this, people put business logic into PHP pages, and often they mistake it for a general-purpose language rather than a domain-specific language. This confusion is what's causing the flame war here.



    (Full disclosure: I write my web pages in Perl, using TemplateToolkit for templating. TT is busy gaining features, and sooner or later, I expect to come across a website written entirely in TT.)



  • @Carnildo said:

    Because of this, people put business logic into PHP pages, and often they mistake it for a general-purpose language rather than a domain-specific language.

    I was with you until this part.  PHP is a general-purpose language and has been for awhile.  It is not domain-specific but it still retains the templating system as well.

     

    @Carnildo said:

    This confusion is what's causing the flame war here.

    Wrong.  The flamewar is because DOA seems to think he needs a templating language on top of PHP and everyone else realizes that PHP has templating built into it.  End of story.



  • @morbiuswilters said:

    The flamewar is because DOA seems to think he needs a templating language on top of PHP and everyone else realizes that PHP has templating built into it.
    Amusingly enough I'm the only one in this little flamewar to have actually used a 3rd party template engine.



  • I realize that this is kind of an out-of-place comment but I just have to ask: what about caching?


    AFAIK, Smarty has a built-in cache mechanism that (supposedly) reduces load times by bypassing reevaluation of the template. While I'm with the "PHP is itself a template language" crowd on the main topic, I keep wondering how this caching can be (easily) achieved in pure PHP.


    Anything obvious that I'm missing?



  • @DOA said:

    Amusingly enough I'm the only one in this little flamewar stupid enough to have actually used a 3rd party template engine.
    FTFY



  • @DOA said:

    @morbiuswilters said:

    The flamewar is because DOA seems to think he needs a templating language on top of PHP and everyone else realizes that PHP has templating built into it.
    Amusingly enough I'm the only one in this little flamewar to have actually used a 3rd party template engine.

    I was trying to convince some people last week that sugar works better in cars than gasoline. Amusingly enough, I was the only one in that little flamewar to put sugar in my gas tank.


Log in to reply