SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Logic and Template Separation

    In working on a framework created by myself and two other people, we decided to employ the latter approach. The resulting architecture had us create two separate files for every one page: an ACTION file (logic) and a PAGE file (template). We all agreed to swear by the following two rules:

    1. ACTION files should never contain any HTML whatsoever.
    2. PAGE files could only use PHP for basic scenario-handling conditionals, outputting data passed from the ACTION file, looping through arrays passed from the ACTION file, and basic functions used to format data passed from the ACTION file.

    In approaching template and logic separation this way, I don't feel anything except success. We've got a solid working system that doesn't have any of the overhead attached with regularly parsing template files, none of the nuisance involved with having to learn yet another obscure templating syntax, but is far more flexible solely because it utilizes PHP itself. If I spent some time improving the caching system for some further speed gains, I can't see how something like Smarty would ever possibly keep up.

    Having said all that, what advantages would using a parsed system like Smarty provide that the above method wouldn't? Am I wrong or too arrogant in my statements?

  2. #2
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the one I use:

    PHP Code:
    <?php
    class View {
        var 
    $data = array();
                
          function 
    set($key$value null) {
            
    $this->data[$key] = $value;
          }
            
          function 
    fetch($filename) {
            
    $file DIR_VIEW $filename;
        
            if (
    file_exists($file)) {
                  
    extract($this->data);

                  
    ob_start();
          
                  include(
    $file);
          
                  
    $content ob_get_contents();

                  
    ob_end_clean();

                  return 
    $content;
            } else {
                  exit(
    'Error: View ' $file ' not found!');
            }
          }
    }
    ?>

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Seikh View Post
    Having said all that, what advantages would using a parsed system like Smarty provide
    This was discussed many times here, you may want to search. In short, the advantages of parsed templates are more convenience and more safety.

  4. #4
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stereofrog View Post
    This was discussed many times here, you may want to search. In short, the advantages of parsed templates are more convenience and more safety.
    I see. Apologies for that.


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
  •