to template or not

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Poley

    #16
    Re: to template or not


    On Thu, 26 Feb 2004 18:27:21 +0100, "rush" <pipa@rush.aval on.hr> wrote:
    [color=blue]
    >"Stephen Poley" <sbpoleySpicedH amTrap@xs4all.n l> wrote in message
    >news:oj3s30tmv o8sgs5a9rcc25il 1cs4bs6vni@4ax. com...
    >[color=green]
    >> Suppose you have a page which has to display a variable-length list of
    >> products. If the length is zero, it puts up a paragraph along the lines
    >> of "no products currently available in this category".
    >>
    >> How do you do that in a template which includes no code?[/color][/color]
    [color=blue]
    >html/prodlist.html:
    ><html>
    ><body>
    ><h1>Phone MegaStore Special</h1>
    >
    ><!--NAME:ONEPRODUCT-->
    >Product Name:{PRODNAME} price: {PRODPRICE}<br> <hr>
    ><!--END:ONEPRODUCT-->
    >
    ><!--NAME:NOPRODUCTS-->
    >Sorry no products found ...
    ><!--END:NOPRODUCTS-->[/color]


    OK, I get the general idea, thanks.

    I think on the whole I'd just as soon as have something like:

    <?php if ($products==0): ?>
    Sorry ...
    <?php endif ?>

    but I can see some people might just prefer your version.

    --
    Stephen Poley

    Comment

    • R. Rajesh Jeba Anbiah

      #17
      Re: to template or not

      "rush" <pipa@rush.aval on.hr> wrote in message news:<c1i6ct$cn 8$1@ls219.htnet .hr>...[color=blue]
      > "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> wrote in message
      > news:abc4d8b8.0 402242214.ec7dc 7c@posting.goog le.com...[color=green]
      > > In this case, if you handle <?=$foo?> as the way you would handle
      > > {foo} (ie, static), then the problem solved.
      > >
      > > If you don't like the looping or conditioning inside the template,
      > > you can just populate the list/content in the variable like
      > > $foo_static_lis t and can just use it in the template. So, my point is
      > > why making our own template engines to *just* to avoid looping &
      > > conditioning---it can be done with PHP itself.[/color]
      >
      > what if $foo_static_lis t needs to use other template, and conditions within,
      > and loops within condition, etc, which happens in most nicely designed
      > pages? What would be a clean way to populate it? Encode tha complex piece of
      > html as a string in php?[/color]

      I didn't say that it's the only way. What I said was, if you prefer
      the markup to be static, you can even do it in PHP--no need to go for
      another markup, another parser, etc. That was my point.
      [color=blue][color=green]
      > > I don't mean adding conditioning & looping logic inside the
      > > templates. I just say: why not use PHP's own markup instead of
      > > inventing our own template markups, parser,.. And even I don't find
      > > anything wrong with adding looping & conditioning inside the
      > > templates--as long as presentation logic and business logic are
      > > separated--Smarty's definition.[/color]
      >
      > Well, if that suits you fine. I do not like code that is intemixed with
      > html. For me it is hard to read, hard to write, and pain to maintain in the
      > same file together with designer. This is the reason I do not use php's own
      > markup, or templates that have programming constructs. If you find that
      > these reasons do not bother you, (and obviously they don't) than just write
      > the way you are.
      >
      > On top of template system I separate presentation logic from bussines logic
      > by MVC or something similar, not by template system.[/color]

      Yes, I understand you may need to go for another layer to manage
      the presentation & logic. But, our aim is to get the simple
      lightweight framework--which I believe can be done with PHP itself,
      but with some isolation of logic. And I understand, YMMV.
      [color=blue][color=green]
      > > <td>{var1}</td><td><b>{var2 </b>}</td> <--note the <b> tag[/color]
      >
      > If it starts happening to me I will think start thinking about it as a
      > problem. But what was happning to me, were the cases when designer cutted
      > away good pieces of php code, moved it in inproper places, or messed it up
      > inadverdently while changing the layout. And that is the problem I have
      > solved by usage of templates.[/color]

      I think, your designer use some other tools. It never happend to us
      'coz we used to separate header & footer--the most touchup work will
      be on a small template (PHP+HTML) code.
      [color=blue]
      > Again, I can understand that you do not prefer or do not have need to use
      > templates, I am fine with that. But just understand that I have a need for
      > them, and that they are for me powerfull and usable, and going back to not
      > use them would feel for me as going back into stone age.[/color]

      I too use a kind of template system. Sometimes ago, I posted my
      script here <http://groups.google.c om/groups?selm=abc 4d8b8.040213054 7.2f09d2af%40po sting.google.co m>
      In usual developement, I hardly (or never) use echo and so it is easy
      for the designer to touch it easily. At a maximum, it require just 3
      phase:

      1. Our code-gen, generates the code (PHP & HTML)
      2. Templating HTML code goes to designer to add "colours" -- hardly
      happens as the code-gen will generate CSS based code.
      or
      1. Designer provides pure HTML template (without any template
      markup)
      2. Developer inserts some PHP templating like <?=$foo?>
      3. Designer gets the PHP powered template and adds "colours" --
      rarely happens as the first HTML template itself will be sufficient.

      When we want to setup a lightweight framework, people prefer even
      too simple system. And right now, we're considering:
      - Henk Verhoeven's template
      <http://groups.google.c om/groups?selm=btv 963%245se%241%4 0news2.tilbu1.n b.home.nl>
      - Brian Lozier's template
      <http://www.massassi.co m/php/articles/template_engine s/> (seems to be
      nice if caching is necessary)
      - or even Harry's simple AwesomeTemplate Engine
      - and moreover, we have to comeup with better system (as it going
      to be proprietary)

      For me, if we prefer some new markup, we may go for Zope or similar
      languages, instead of inventing them in PHP itself. I understand, many
      people prefer to stay in PHP, but like to use other kind of
      templating.

      p.s: Apologies for late follow-up; I was so busy.

      --
      "Success is not what you achieve, but it is what you die for"
      If you live in USA, please support John Edwards.
      Email: rrjanbiah-at-Y!com

      Comment

      Working...