Which way of setting up templating would you choose?

Discussion in 'PHP' started by squishi, Jan 17, 2010.

  1. #1
    I use a template engine called "outline" for a web project.
    Outline has two ways of setting up templates.

    The first way:
    require "config.php";
    $outline = new Outline('templatename');
    require $outline->get();
    PHP:
    In this case, all the variables of the php file will be available in the template 'templatename'.

    The second way is the traditional way of templating:
    require_once "config.php";
    require_once OUTLINE_CLASS_PATH."/tpl.php";
    $test = new OutlineTpl('products');
    $test->assign('title', 'Fancy Dandy Product');
    $test->display();
    PHP:
    I am used to this second version, as it is similar to smarty.
    Variables need to be assigned to the template before they can be used in the output.

    Which way of templating would you suggest to use for a production website?
    The second version seems more secure to me, whereas the first version would make the code more clean and maintainable (because there is no need to assign variables to a template before using them).
     
    squishi, Jan 17, 2010 IP
  2. CodedCaffeine

    CodedCaffeine Peon

    Messages:
    130
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Disclaimer: I've never heard of Outline before, so I'm just basing what I say from how I feel it should be done.

    The first one has less lines, but you're not able (I believe) to assign the variables dynamically in the PHP code itself (The page that you're running this code on).

    The second way allows for you to dynamically assign those variables. The disadvantage that I see is it would be slower than the first one because it requires you having to set the OutlineTpl instance, then add a variable, and output it.

    Overall, I don't see any real issue in security for picking one over the other, but if you want speed, I'd personally go with the first one. If I wanted to assign something via my PHP code, I'd go with the second one.
     
    Last edited: Jan 17, 2010
    CodedCaffeine, Jan 17, 2010 IP
  3. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I would choose the second method every time to be honest. I'm a smarty fan and believe in the concept of keeping view and processing separate. Using the first method just eliminates that and allows anything to be in the template, which could have major implications should there be a design and a development team working on each section individually, and the design team use vars they shouldn't
     
    JAY6390, Jan 17, 2010 IP
  4. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #4
    I agree with JAY6390 and would recommend 2nd method only.

    I have been through tough times separating out view from logic in past and hence whenever I use templates, I assure to have a method like Smarty to keep them separate.
     
    mastermunj, Jan 17, 2010 IP
  5. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    no body hearing about this new templete engine
    but i know all templetes engine
    why
    becuase thay store here
    and there is many you can get any other one
     
    astkboy2008, Jan 18, 2010 IP
  6. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Another shameless plug. He already has the Templating engine so why would he need it again? Also if you're going to link it link to the proper page
    http://code.google.com/p/php-outline/
     
    JAY6390, Jan 18, 2010 IP
  7. squishi

    squishi Peon

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks for the replies (except for the spam from astkboy). ;)
     
    squishi, Jan 18, 2010 IP
  8. php.freak

    php.freak Well-Known Member

    Messages:
    185
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #8
    hey every one I want to delete select rows from the table using php.Same way what we do in hotmail or gmail.

    thanx
     
    php.freak, Jan 18, 2010 IP