Women in Technology

Hear us Roar



Article:
  The Dynamic Duo of PEAR::DB and Smarty
Subject:   This is not separating logic from presentation
Date:   2003-04-22 22:22:07
From:   anonymous2
When you still have logic expressions in the HTML, this is not separating logic from presentation.


If you ask most HTML designers that do not understand your HTML templates because they still have programming logic in them.


This is a thing that usually developers that work alone have like the article author do not understand because they are used to do both the programming and the presentation design.

Full Threads Oldest First

Showing messages 1 through 9 of 9.

  • This is not separating logic from presentation
    2003-04-23 19:59:26  jcpm [View]

    As I said in the article, presentation logic is very different from business logic. I see nothing wrong with allowing the designer or programmer to separate the logic in which a row gets a different color, for instance.

    From personal experience, having presentation logic in the PHP code eventually gets confusing and messy. Why should I have to loop through blocks as it is done in PHPLIB just to set a placeholder to have the color #CCCCCC or #999999.

    But most of all, this is personal opinion. Templating systems should be chosen by what you feel comfortable using, and some people may prefer Smarty and some people may prefer PHPLIB or some other system.

    Cheers,
    Joao Prado Maia
    • This is not separating logic from presentation
      2003-04-25 00:55:18  anonymous2 [View]

      The problem is not in the template engines but in the way programmer use them.

      The presented example is very clear that in the end it will always be the same person doing the presentation and the logic. This means that if you want to alter the logic, you need to alter the presentation templates.

      Consequently, it will be more expensive to companies that work that way because it has all to be done by a single person that needs to know 3 languages: PHP, HTML and the template engine language.

      For people that deal with that, it may be just fine, but people with that many qualifications are harder to find, charge more and stall the development more because all the work is dependent on them.

      Bottom line, messing three languages to use a template engine is a very inneficient and expensive way of work. Only people that work alone have an hard time understanding this.
      • This is not separating logic from presentation
        2003-07-29 02:26:04  anonymous2 [View]

        >This means that if you want to alter the logic, you need to alter the presentation templates.
        Not true. You still do not see the difference between the two logics involved. when you do a script that needs a template you write the code on the script, then you pass the needed vars to smarty. if you change the original code as much as to have the necessity of changing the logic on the template is your own fault - that may occur because you didnīt thought well of the use of that script.
        anyway, letīs say that your boss says you "ok, now change it because I'm a big kick4ss". you have to change the script and the template. but you would also need to do it if you embed the html on the script making the task much harder.
        @about template syntax for html coders
        if you know to code on HTML you certainly can understand how to use {if (something)}foo{/if} or maybe {section loop...}. that two functions, plus literal and comments {* are the most I use. I think that it is not precissely about learning assembler...
        .:c0p0n:.
  • This is not separating logic from presentation
    2003-04-23 10:09:22  anonymous2 [View]

    There is more than one type of logic. The idea behind templates is to remove business logic from your presentation. Not to remove presentation logic from your presentation. There is a bunch of logic that has every right to be in the templates - such as alternating table row colors, theme selection, special messages, etc. This has nothing to do with the business logic or data access. Try this:

    http://www.massassi.com/php/template_engines/
    • This is not separating logic from presentation
      2003-04-23 17:18:23  anonymous2 [View]

      No, you are not getting the point. Any logic flow control should not be in the templates because this simply rules out that majority of the real presentation designers.

      If you need to iterate over the same template, like in alternating table row colors, just do it in the programming. That is what programming is meant to be, control the program output logic flow.

      Template engines like Smarty that make you handle any logic in the templates are not a great improvement over the traditional PHP programming. They require you to learn a third language that is neither PHP nor HTML.

      Properly conceived templates should only contain HTML, placeholders and delimiters, so they can be edited in any HTML editor and any good graphic designer can do his job and not have to learn that third language.
      • This is not separating logic from presentation
        2003-05-06 04:32:20  anonymous2 [View]

        Well, you're right when you say:

        If you need to iterate over the same template, like in alternating table row colors, just do it in the programming. That is what programming is meant to be, control the program output logic flow.


        However, how should the programmer know which color to iterate over and how to specify it? It's the HTML designers job to say "use color a and b". The programmer tells the designer that this row will be repeated for an unknown number of times and then the HTML designer has to come up with a good representation.

        I don't see what's wrong with this.

      • This is not separating logic from presentation
        2003-04-24 09:14:15  anonymous2 [View]

        >> Any logic flow control should not be in the templates...

        I felt exactly the same way for a very long time. I had heard of smarty for months before I ever actually tried it. I didn't like it. Putting looping constructs inside a html file! WTF?!

        However, I decided to just try it because of all the rave reviews I had seen and I'll never go back.

        Trying to wrap my head around the fact that there is 'code' in the html was tough. This method was as bassackwards as I could imagine. I stuck with it though...I just made some example pages to become familiar with it then I modified some existing pages from phplib to smarty and WOW. The ease of editing the smarty pages and the power available in smarty changed how I've programed every php application since.

        So, my advice is to try it out. It may not be for you....I didn't think it was for me, but damn was I wrong.

        Tom
        • This is not separating logic from presentation
          2003-06-05 12:40:35  anonymous2 [View]

          I totally agree.

          I needed a way to seperate the presentation data and logic from the business logic... since someone else will be editing the html after I am done with the code.

          I thought of simply printing the HTML myself and allowing them to change it via CSS. However, this proved to be cumbersome. It allowed them to only change the look of components, and not change the components themselves... plus the CSS files were getting to be too big.

          So I read an article on slashdot.org yesterday about seperating business logic and presentation. One of the comments linked to this article as well as the Smarty site. I was a bit skeptical.. thinking I would probably just write my own template engine. However, I gave Smarty a shot after reading this article, as it seemed very easy to use and very easy to learn (face it, for an experienced programmer, the "language" takes 2 seconds to learn). I LOVE it so far. It has made me feel so much better about writing my code and not worrying about the presentation. It will be easier for the guy who I'm writing this for to manage.. he does know some programming, so it's not like the templates will baffle him.

          I appreciate this article and wholy recommend Smarty to anyone to wants a good templating engine with some power. Given that speed isnt critical that is.
          • This is not separating logic from presentation
            2003-07-10 00:18:36  anonymous2 [View]

            I agree too.
            As a graphic designer, Smarty seems very good solution for templating. The good point of Smarty is that, when the designer wants to change a color or any visual aspect of presentation, he can do it without asking to programmer, without touching to any program code.

            Actually I work for a web site with PHPLIB. I have to switch between template files and php codes in order to change/preview/confirm and I'm sure if, after my changes in the php code, everything goes still fine in the business logic side...