SitePoint Sponsor

User Tag List

Page 1 of 4 1234 LastLast
Results 1 to 25 of 88

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2003
    Location
    Albuquerque, NM
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Template Engine or HTML with embedded PHP?

    I am writing a CMS for our intranet (I have my reasons) and now that I have a basic flowchart of the app, I need to decide how to display information.

    In the past, I've always used the Smarty template engine, but that's only because I found a good tutorial on it, not because I have any clue on performance, features, or ease of development.

    A good support community is important to me, as well as the ability to loop through arrays. (I loves me some arrays.)

    I could also simply do everything in HTML with PHP, but you know, that whole "separate code from design" thing.... which means I'd also like a template engine where the templates could be developed by non-coding designers.

    Tips or advice?

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really recommend you reading this good old thread, and especially the things voostind says:
    http://www.sitepoint.com/forums/showthread.php?t=67849

    Does anyone know what voostind is doing these days?

  3. #3
    SitePoint Zealot romance's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you've used smarty then you'll know you can never seperate code from design completely - you still have conditionals, loops etc, but just with slightly different syntax. As long as your not making db calls/busness logic in the html then theres no reason not to use php as the templating engine.

    The question you have to ask yourself is, whats easier to learn from a designer perspective

    <?=$title?>

    or

    {$title}

    and is that ease of use worth the speed overhead of a big templating engine?

    you can read some more at http://www.massassi.com/php/articles/template_engines/ which also includes a php template engine with caching in 40 lines of code

  4. #4
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by OneSeventeen View Post
    that whole "separate code from design" thing...
    As Romance said above, this doesn't exist. Actually, it's a common misconception -- replace it with "separate business logic from presentation logic" and things should be much more clear.

  5. #5
    SitePoint Member
    Join Date
    May 2003
    Location
    Albuquerque, NM
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting reads, thanks for pointing me in the right direction.

    I didn't want to use a template engine, because I have a simple method in mind, but I wanted to make sure and follow a "best practice" for anyone who might need to modify the site in the future.

    I will still separate the logic into a header file, but will display it in html with php tags rather than adding an extra unnecessary layer.

  6. #6
    SitePoint Addict chestertondevelopment's Avatar
    Join Date
    Dec 2005
    Location
    Essex, UK
    Posts
    241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're looking for something a designer can use, I'd recommend you go with Smarty. Personally, I use a pure PHP solution but Smarty is good for designers and provides no noticeable overhead over a pure PHP solution as after the first time a template is rendered, it's "compiled" into native PHP code which is then run on subsequent requests, meaning it doesn't have to parse the code again.

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's a common myth that smarty is better for designers. But as all myths, it's hard to think that the world would continue without.

    Write your application that you can change the template engine at any time. Personally i prefer php. Designers i work with are not so stupid to handle a couple of php code lines. And you can even secure your php templates against unwanted code.

  8. #8
    SitePoint Addict chestertondevelopment's Avatar
    Join Date
    Dec 2005
    Location
    Essex, UK
    Posts
    241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by atu
    it's a common myth that smarty is better for designers.
    I don't think you can claim it's a myth, it's after all a personal preference. Many designers I've worked with prefer it, it's what they know and it's what they're comfortable with. Some will run a mile if they see <?php echo $content; ?> I know it doesn't make sense to us and I agree, I'd choose pure PHP templates every time over Smarty and I do more often than not, but if I'm working with a designer who prefers Smarty, why not let them work with what they're comfortable with?

  9. #9
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stardustwd View Post
    Some will run a mile if they see <?php echo $content; ?>
    Let them run. Never i will stop such sensible souls.


    Quote Originally Posted by stardustwd View Post
    .... why not let them work with what they're comfortable with?
    until they write spaghetti code. yes this is also possible with smarty.

  10. #10
    SitePoint Evangelist tetsuo shima's Avatar
    Join Date
    Oct 2005
    Location
    Switzerland
    Posts
    597
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stardustwd View Post
    I don't think you can claim it's a myth, it's after all a personal preference. Many designers I've worked with prefer it, it's what they know and it's what they're comfortable with. Some will run a mile if they see <?php echo $content; ?> I know it doesn't make sense to us and I agree, I'd choose pure PHP templates every time over Smarty and I do more often than not, but if I'm working with a designer who prefers Smarty, why not let them work with what they're comfortable with?
    Hi
    Personnaly, I don't believe in it. If I ever work with such designers, I'll make them run. Wordpress is most probably the app that is the target of choice of designers when it comes to create themes. And...and...and... (drums roll) here's the index file:
    PHP Code:
    <?php get_header(); ?>

        <div id="content" class="narrowcolumn">

        <?php if (have_posts()) : ?>

            <?php while (have_posts()) : the_post(); ?>

                <div class="post" id="post-<?php the_ID(); ?>">
                    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                    <small><?php the_time('F jS, Y'?> <!-- by <?php the_author() ?> --></small>

                    <div class="entry">
                        <?php the_content('Read the rest of this entry &raquo;'); ?>
                    </div>

                    <p class="postmetadata"><?php the_tags('Tags: '', ''<br />'); ?> Posted in <?php the_category(', '?> | <?php edit_post_link('Edit'''' | '); ?>  <?php comments_popup_link('No Comments »''1 Comment »''% Comments »'); ?></p>
                </div>

            <?php endwhile; ?>

            <div class="navigation">
                <div class="alignleft"><?php next_posts_link('&laquo; Older Entries'?></div>
                <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;'?></div>
            </div>

        <?php else : ?>

            <h2 class="center">Not Found</h2>
            <p class="center">Sorry, but you are looking for something that isn't here.</p>
            <?php include (TEMPLATEPATH "/searchform.php"); ?>

        <?php endif; ?>

        </div>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>
    Of course, Wordpress is not super OO friendly and things could be improved, but it's the proof that designers can work around a bit of php. And if they can't, fire them, or ask them to learn. After all, if they've got through the w3c specs (which any good designer has done, as we all know) a bit of echo and looping shouldn't be the end of the world.
    I personnaly don't see the need for a template engine.
    The SEO Faq thread
    Dependency injection made easy: Phemto

  11. #11
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The company I work for has quite a few CMS installations of XOOPS, Joomla and a few other systems. In the case of a CMS, you aren't just dealing with designers. You are dealing with some poor slob office employee that was chosen to be the one to update the web site with the software. In our experience Smarty is much easier for them to alter in Dreamweaver, Contribute or within the CMS interface itself for those people.

    Our designer can use either, but if a page has too much PHP, it gets sent to me to alter and spend my time on. I don't blame her. She's an excellent designer, but comes from more of a graphics, Photoshop background rather than from a coding background. It's not my job to teach her PHP.

    Having said that, though there is definitely a good reason why so many open source CMS systems use a template engine such as Smarty, Major applications such as CMS, CRM and other packages are moving to framework based systems, now that there is enough maturity in the code and more hosts have moved to PHP v5.x.

  12. #12
    SitePoint Addict chestertondevelopment's Avatar
    Join Date
    Dec 2005
    Location
    Essex, UK
    Posts
    241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by atu
    until they write spaghetti code. yes this is also possible with smarty.
    I don't see how a template system relates to spaghetti code at all tbh. I use the MVC pattern and the template fits into the View part, meaning there will be no business logic there to spaghettify (TM).

    Surely using PHP would make it easier to create spaghetti code anyway? I'd like to clarify that I don't think Smarty is a better option than PHP templates, I'm just saying some designers are more comfortable with it, and if I don't have to do anything with the templates, why not let them do it? With compiled templates there is no (or very very little) overhead, which is the main reason people people prefer PHP templates. I'd also like to point out that I've worked with designers who are equally comfortable with Smarty as they are with basic PHP syntax and I would choose the PHP solution every time.

  13. #13
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I personally use smarty in my larger projects. I find it useful to assure that the templates actually does not do anything else than presentation logic, something that you can control quite well with smarty.

    If the designer has access to the whole PHP API it is easy for a designer and hobby PHP-coder to do logic that should be at an other layer.

    But in the end this is mainly personal preference as you say. I like smarty because I find smarty templates much easier to read and purer than mixed mode PHP/HTML.

  14. #14
    SitePoint Zealot romance's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stadskle View Post
    If the designer has access to the whole PHP API it is easy for a designer and hobby PHP-coder to do logic that should be at an other layer.
    They can still do this in smarty, just by using {php}, but i'd be more concerned why the designer would be doing any logic apart from conditionals/looping as it would show flaws in my own code.

  15. #15
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I prefer to keep my client side code seperate from my server side code, so using a template engine is great for me and my projects.

    Its all a matter of preference. If you enjoy weeding through your code to make your application and interface code changes, because that's what you are familiar with, then a template engine might not be for you.

  16. #16
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    368
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ive recently been moving more and more of the UI layer to the clients browser


    so pretty much the server side just takes data using GET/POST processes it (using own MVC framework) and responds with json encoded data

    on the client side the UI us rendered with help of YUI/Jquery


    the above has cut down the amount of UI generated on the server side and shifting the task to the client, making my life alot easier

  17. #17
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mihd View Post
    ive recently been moving more and more of the UI layer to the clients browser

    so pretty much the server side just takes data using GET/POST processes it (using own MVC framework) and responds with json encoded data

    on the client side the UI us rendered with help of YUI/Jquery

    the above has cut down the amount of UI generated on the server side and shifting the task to the client, making my life alot easier
    So the complete app is generated by javascript? Do you realize this will affect the performance of your app differently on each system? Plus it comes with a lot of difficulties with cross browser/platform compatibility. I recommend javascript/XHR, but only when it's used correctly: to transfer small bits of data.

    [ontopic]
    I've been experimenting with a template renderer based on DOMDocument. The designer can create html/css templates, and maintain those. The DOMTemplate parser will load the template and inject content using ID's. A bit like the javascript/xhr method to dynamicly inject content. This way, the designer can insert dummy content to view prototypes, and still be editing the template which is used in production.

    I'm still fine tuning it, and deciding whether it's useful or not. It's nice for designers to create purely HTML/CSS templates and maintain those. But on the other hand it requires some more coding to inject content properly. Hmmm...

    Oh and btw, i'm still searching for a css-selector class in PHP, based on XPATH. For adding support for alternative selectors than only by ID. Did a lot of searching, but it seems no one has published anything like this. How nice would it be to do something like this, $quotes = Nodes::bySelector( "span.quote"); which returns an array with all matched objects. Combined with a DOMTemplate parser this could be very useful!
    [/ontopic]

  18. #18
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by p.vernooij View Post
    I've been experimenting with a template renderer based on DOMDocument. The designer can create html/css templates, and maintain those.
    The biggest problem with that, is probably performance.

    Quote Originally Posted by p.vernooij View Post
    Oh and btw, i'm still searching for a css-selector class in PHP, based on XPATH. For adding support for alternative selectors than only by ID. Did a lot of searching, but it seems no one has published anything like this. How nice would it be to do something like this, $quotes = Nodes::bySelector( "span.quote"); which returns an array with all matched objects. Combined with a DOMTemplate parser this could be very useful!
    Why won't you use Xpath? CSS-selector is essentially just a dumbed-down version of XPath.

  19. #19
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    The biggest problem with that, is probably performance.
    Yeah i worrie about that too. But i think i can cache a lot (server side) to spare render time. Combined with proper ETag usage and 304 Not Modified headers, i think the performance won't be a big issue. Still investigating
    Quote Originally Posted by kyberfabrikken View Post
    Why won't you use Xpath? CSS-selector is essentially just a dumbed-down version of XPath.
    Hmm i think i'm just too used to javascript didn't use XPath for anything yet. Looked into the documentation a bit, and found out it was quite another style than css-selectors. Css-selectors are just too easy to use, and fit perfectly for what i need. I'll do a bit more researching on XPath, seems it's the only option available at the moment.
    Last edited by p.vernooij; Dec 28, 2007 at 04:43.

  20. #20
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see anything wrong with using smarty so that the designer feels comfortable. Of course those suggesting to just tell the designer to tough it out or find another one I question if they've produced anything that's actually in production.

    Designers are comfortable with smarty syntax even though it's hardly different than PHP. We'd all love to see just PHP based templates, but it's not going to happen. So we'll live with a .tpl file that smarty engine turns into a .php which is actually parsed. Is it really that big of a deal?
    Quality Shared and Reseller Web Hosting
    Cpanel/WHM RvSkins Fantastico de Luxe 24/7 Support
    PHP5 Zend Framework PDO Ruby On Rails Subversion Trac
    Hawk Host Inc. Quality Web Hosting Since 2004

  21. #21
    Non-Member Musicbox's Avatar
    Join Date
    Nov 2004
    Location
    india
    Posts
    1,331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    template system for cms is required but if you use smarty it has to work in all php versions

  22. #22
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'm with the 'use PHP with HTML' crowd here. Template engines are unnecessary bloat.

  23. #23
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider View Post
    I'm with the 'use PHP with HTML' crowd here. Template engines are unnecessary bloat.
    Wouldn't code bloat be embedding client-side code in your server-side code?

  24. #24
    SitePoint Enthusiast B00MER's Avatar
    Join Date
    Mar 2002
    Location
    Ft. Worth, Tx.
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Personally I like Smarty, its less clunky than embedded PHP logic. It is a curve but I think it is worth it. Some major advantages I think a template engine has, for one is I can easily duplicate a skin or template directory modify it for whatever reason and have multiple skins for one web app without alot of change on the business logic side of things. I am what most would call a rare breed, I do alot of designing and coding myself. So I do see how it can be a double bladed sword. I do lean more towards designing than coding but thats just what I enjoy personally. I see alot of people arguing that the templates are still not xhtml compliant, you can easily change the begin/end tags of smarty. Really all this is explained at: http://smarty.php.net/whyuse.php and makes some valid points on why to use, of course they are going to sell you on using it without any of the disadvantages. One thing I know that should ALWAYS be avoided with smarty templates is the {math} tag as it uses the evil eval(); Even with a php accelerator alot of these tags can really kill the template engines performance. The documentation even notes this as well...

    http://smarty.php.net/manual/en/lang...ction.math.php

    Just my 2cents... opinions are like butts we all have them and they all stink.

  25. #25
    SitePoint Member
    Join Date
    May 2003
    Location
    Albuquerque, NM
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After taking into consideration my project, I have decided to stick with HTML + PHP. (Once again, due to my current project, I realized I'd practically be making a different template for each page anyway, so why not stick with HTML.)

    Also, The type of designer I've worked with in the past that was confused by PHP tags were also eager to show me their awesome flash-only websites and WYSIWYG created designs.

    Here we've got a web team that takes the graphic designer's concepts (usually PSD files) and turns them into a web page. This is awesome because in the organization it separates design from code. All of our web developers are coders, so I don't really have to worry too much about that anyway.

    I've designed rather large applications used by a major university using the Smarty template engine, and I liked it, but having played with Drupal and Wordpress templates it is so incredibly easy to simply print variables, or call methods from my class.

    I've also got some techniques I use to create cached pages that is incredibly basic and pretty quick to load. (Basically it checks for a generated file, checks to see if it is older than the cache expiration, and if so, rebuilds it, if not, just display the existing html page, pretty simple.)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •