Well I am just going to start on a new project, it is pretty complex but I need to build it quickly. Over the past few weeks I have been looking at various discussions on the net as to the usefullness of using a template engine.

From what I can see, it's not that much better using templates, it's much more complex trying to use DB information, you have to learn a whole new set of tags and commands, plus you still have all these template tags in your HTML so you may as well have PHP tags in there?!?

Ideally I wanted to make my new development in a modular fashion similar to a PHP-nuke type thing, so I can use blocks to define the position on certain modules etc.

Any ideas or suggestions? Smarty looks ok but the lack of DB support scares me! I mean to simply display a set of results seems like a nightmare! 🙁

    Some template engines are great for rapid development, so long as they suit the needs of your application. Unfortunately, templates are designed to satisfy the needs of the majority, so they may not work for everyone, and may even prove to be more of a headache.

    I use templates on websites that I build becuase after spending a good deal of time for the initial construction, I can put up a site relatively quickly using the same template every time. But that's not to say that it would work for a website that wasn't designed using the same standards (header, footer, directory structures, etc.) as the ones I've done.

    Ask yourself a few questions:

    1) Do you really need multiple database support?

    2) Will your application work w/ existing templates without spending a lot of time re-thinking the design?

    3) Are you comfortable enough with php to modify/troubleshoot the template as you see fit?

    4) Is your application big enough to warrant the use of a template engine, or would you be swatting a fly with a baseball bat?

    Just some things to think about...

    --Brad Fears

      I don't need support for multipule DB's although I do need one mySQL DB.

      This application I am starting from fresh, which is why I have considered using a template engine.

      Im comfortable with php, but Im not really comfortable using classes as I have never had the need before, I just coded my own functions. Im sure I can get used to them pretty quick but the whole structure thing of using a class seems a little overcomplicated to me, with no particular reason why it should be.

      Yes, the application is big enough. It will be a site with auction style sales (maybe 20 items or so), it needs to use some form of e-commerce and registered user login system, member download area etc.

      I have been thinking maybe I would be better to make some type of PHPnuke modified site. Looking more and more at this Smarty class, it seems to make things really over-complex, I mean just displaying a product page with a list of users currently waiting for an item, and limiting to 25 records per page seems impossible. Something like that which I could do in 10 mins in PHP would take me forever to work out.

      I really want to use templates so that I can change the look later on without effecting the structure, but reading articles by some very good PHP programmers suggests that templates are no more than a gimmik which in reality don't properly seperate code from design anyway (still have to use template IF tags etc).

        There is a compromise position.

        I'm working on a moderately complex site. At some point I may want to have other people be able to customize the look and feel of the pages. However, I also feel that existing template engines are overkill.

        I have partitioned the application. The first portion simply gathers up data and tucks it away without much concern for the output.

        Then, for each displayed page, I have a template file. The template file is mostly html sprinkled with <? echo $whatever> elements. I try to minimize the php code in the template file. If I find it's getting too complicated then I move it out of the file.

        In theory, if I ever do need to switch to say Smarty then I should be able to swap out the template files and continue on my way.

          you do not need to use a template engine in order to use templates.

          I never use a template engine, I hate them everything seems to come out looking the same or at least similar through them. However, I always use templates. here is a very simple solution.

          Step 1) Design the site.
          Step 3) Break it into three logical sections, static header, static footer and dynamic data section.
          Step 3) Create header.php that contains the header code, and footer.php that contains the footer code. Make sure the header.php contains this line <title><?echo $title?></title>
          Step 4) In your scripts do this
          $title = 'name of page';
          include('header.php');
          all your fancy dancy php here
          include('foorter.php');

          look a roll your own template engine in four steps. BTW: anything that may change such as the path to images and your style sheet can also be stuck in variables but this should be kept to a minimum or it's starts to loose its benefit.

            • [deleted]

            I agree with drawmack. The majority of things I build anymore follow this method. My own simple template system...

              Thanks guys, I was supposed to take a closer look at smarty last night but I was so tired when I got in from work that I fell asleep at 8pm.

              SO anyway, I will take a closer look at smarty today, I will read toma42's article. If that looks a bit like overkill than I believe I will take a look at using a similar system to drawmack.

              Thanks again, if any of you think of anything else don't hesitate to say, I won't be starting building the site for a few more days.

              Justin.

                Am I correct in assuming that you cannot use frames/iframes with smarty?

                  a month later

                  What did you end up using?
                  We're about to do a rewrite and I started looking at FastTemplates...
                  but from what I can see it doesn't handle PHP 4.3.0 up.. http://www.phpbuilder.com/board/showthread.php?threadid=10228973&highlight=FastTemplates
                  and conflicting?
                  http://www.phpbuilder.com/board/showthread.php?threadid=10234597&highlight=FastTemplates
                  BUT I haven't tried... just trying to get ideas!
                  Did you end up using Smarty? good things?
                  Bad Things?

                  Thanks
                  Beth

                    4 months later

                    I am also using my own type of templating system where by I create the layout of the page and then call the main, changing pages into that page. The problem that I have is that if I have a page which needs to start a session, I get error's i.e. headers allready sent. I really like this way of doing things as it is really quick and easy to change the entire layout of the site in one file. I was wondering if anyone could offer some help with how I can get around this.

                    Thanks inadvance
                    dill

                      Write a Reply...