PHP Templating Systems and Conditional HTML

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

    #1

    PHP Templating Systems and Conditional HTML

    Which of the popular templating systems (e.g. PHLib, FastTemplate,
    Smarty) allow you to setup conditions in your templates, for example:

    <-- IF Variable=value -->
    this HTML
    <-- ELSEIF Variable=value -->
    this HTML
    <-- ENDIF Variable=value -->

    --Bruce

  • Kevin Thorpe

    #2
    Re: PHP Templating Systems and Conditional HTML

    Bruce wrote:[color=blue]
    > Which of the popular templating systems (e.g. PHLib, FastTemplate,
    > Smarty) allow you to setup conditions in your templates, for example:
    >[/color]
    php does this fine on it's own

    <?php IF ($Variable=valu e) { ?>[color=blue]
    > this HTML[/color]
    <?php } else if ($Variable=valu e) { ?>[color=blue]
    > this HTML[/color]
    <?php } ?>

    Comment

    • MrPlow

      #3
      Re: PHP Templating Systems and Conditional HTML

      Bruce wrote:
      [color=blue]
      > Which of the popular templating systems (e.g. PHLib, FastTemplate,
      > Smarty) allow you to setup conditions in your templates, for example:
      >
      > <-- IF Variable=value -->
      > this HTML
      > <-- ELSEIF Variable=value -->
      > this HTML
      > <-- ENDIF Variable=value -->
      >
      > --Bruce
      >[/color]

      IMO the main purpose of using templates is to separate your logic from
      your layout.

      Having said that, I know that FastTemplate, or DTemplate (my own
      template class which is almost functionaly identical to FT) can
      accomplish what you want using their dynamic block functionality.

      example using DTemplate:

      template.tpl:

      <DTDYN:block1 >
      block1 html
      </DTDYN:block1>
      <DTDYN:block2 >
      block2 html
      </DTDYN:block2>

      template.php:

      <?php
      $tpl = new DTemplate('path/to/tpl/file');
      $tpl->define_templat es(array('body' => 'template.tpl') );
      $tpl->define_dynamic ('block1', 'body');
      $tpl->define_dynamic ('block2', 'body');
      if ($var = true)
      {
      $tpl->clear_dynamic( 'block1');
      }
      else {
      $tpl->clear_dynamic( 'block2');
      }
      //process template stuff and print
      ?>

      dtemplate doc: http://desolatewaste.com/projects/dtemplate/readme.htm
      fasttemplate doc: http://www.thewebmasters.net/php/FastTemplate.phtml

      Comment

      • Andy Hassall

        #4
        Re: PHP Templating Systems and Conditional HTML

        On Thu, 11 Mar 2004 13:22:34 GMT, Bruce <brucev2@hotmai l.com> wrote:
        [color=blue]
        >Which of the popular templating systems (e.g. PHLib, FastTemplate,
        >Smarty) allow you to setup conditions in your templates, for example:
        >
        ><-- IF Variable=value -->
        >this HTML
        ><-- ELSEIF Variable=value -->
        >this HTML
        ><-- ENDIF Variable=value -->[/color]

        Smarty certainly does.

        --
        Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
        <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>

        Comment

        • Andy Hassall

          #5
          Re: PHP Templating Systems and Conditional HTML

          On Thu, 11 Mar 2004 18:54:33 GMT, MrPlow <desolate19@hot mail.com> wrote:
          [color=blue]
          >IMO the main purpose of using templates is to separate your logic from
          >your layout.[/color]

          But layout itself can need 'logic' - depending on how you define 'logic'.

          Templates IMO are to separate your 'data logic' from your 'presentation logic'
          - for presentation beyond the trivial 'loop round an array and print a table
          cell per entry' having some sort of basic code support in the template can be
          useful, else you end up pushing presentation information into your 'data
          logic', where it doesn't really belong.

          Depends on your view of things, of course, which is why there are a million
          and one templating systems that each work according to the opinion of their
          author on this issue. :-)

          --
          Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
          <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>

          Comment

          • MrPlow

            #6
            Re: PHP Templating Systems and Conditional HTML

            Andy Hassall wrote:
            [color=blue]
            > On Thu, 11 Mar 2004 18:54:33 GMT, MrPlow <desolate19@hot mail.com> wrote:
            >
            >[color=green]
            >>IMO the main purpose of using templates is to separate your logic from
            >>your layout.[/color]
            >
            >
            > But layout itself can need 'logic' - depending on how you define 'logic'.
            >
            > Templates IMO are to separate your 'data logic' from your 'presentation logic'
            > - for presentation beyond the trivial 'loop round an array and print a table
            > cell per entry' having some sort of basic code support in the template can be
            > useful,[/color]

            You've got me there. I considered not including dynamic blocks in my
            class at all, but even I used them constantly when I was using
            FastTemplate, so I can't deny that it would probably be even more useful
            to have extra logical controls in the templates, just haven't tried it.

            My goal was to have templates that could be edited by people who know
            how to use Dreamweaver, but have never programmed anything like PHP before.
            [color=blue]
            > else you end up pushing presentation information into your 'data
            > logic', where it doesn't really belong.
            >[/color]

            Not necessarily. I've come up with a bunch of ways to separate them...
            I think I'm nearing a method that I wouldn't mind using more than once
            too! :P
            [color=blue]
            > Depends on your view of things, of course, which is why there are a million
            > and one templating systems that each work according to the opinion of their
            > author on this issue. :-)
            >[/color]

            Yep.

            Comment

            • Jochen Daum

              #7
              Re: PHP Templating Systems and Conditional HTML

              On Thu, 11 Mar 2004 13:22:34 GMT, Bruce <brucev2@hotmai l.com> wrote:
              [color=blue]
              >Which of the popular templating systems (e.g. PHLib, FastTemplate,
              >Smarty) allow you to setup conditions in your templates, for example:
              >
              ><-- IF Variable=value -->
              >this HTML
              ><-- ELSEIF Variable=value -->
              >this HTML
              ><-- ENDIF Variable=value -->
              >
              >--Bruce[/color]

              My personal redevlopment of Fasttemplate does. The templates also
              validate as HTML, because they use <!-- -->

              See my signature,

              Jochen

              --
              Jochen Daum - Cabletalk Group Ltd.
              PHP DB Edit Toolkit -- PHP scripts for building
              database editing interfaces.
              http://sourceforge.net/projects/phpdbedittk/

              Comment

              • R. Rajesh Jeba Anbiah

                #8
                Re: PHP Templating Systems and Conditional HTML

                Bruce <brucev2@hotmai l.com> wrote in message news:<dvp050lnr 71iaev2k9g4ikis cqf7pg5dlr@4ax. com>...[color=blue]
                > Which of the popular templating systems (e.g. PHLib, FastTemplate,
                > Smarty) allow you to setup conditions in your templates, for example:
                >
                > <-- IF Variable=value -->
                > this HTML
                > <-- ELSEIF Variable=value -->
                > this HTML
                > <-- ENDIF Variable=value -->[/color]

                The most popular template system is PHP itself. This topic and the
                suggestions are often disputed at least bye someone. For more info,
                see the recent discussions on this topic
                <http://groups.google.c om/groups?threadm= c17ndg%24l3t%24 1%40newsreader. mailgate.org>

                The important thing here is people often change their styles and so
                their template system.

                <trivia>When Jochen and I had a discussion about template system
                about a year ago, he was backing Smarty. But, now he came up with
                another system :-)</trivia>

                --
                "I don't believe in the God who doesn't give me food, but shows me
                heaven!"--Swami Vivekanandha
                Email: rrjanbiah-at-Y!com

                Comment

                Working...