No announcement yet.

PHP Questions about Templates and Such

  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP Questions about Templates and Such

    Firstly, I've been thinking about a template system. I don't want to use the pre-made template systems, as they would be either too outdated or too large.

    I was thinking about the template system that vB uses, and was wondering how it worked.

    Let me see if I explain it correctly without browsing through the code (in which i will fail).

    First store all templates in database.
    Then you have a function to get the template
    somewhere along the line, you have to evaluate the {stuff} in the templates.

    Do you do this via the explode & preg_replace functions? If so, how? would it be like this

    PHP Code:
    $explodedstuff explode("{",$template);
    foreach (
    $key as $value){
    $explodedstuff2 explode("}",$explodedstuff[$value]);
    assigning part mentioned below here

    then you can get the stuff between the { and }. Then what do you do? Some of those variables are other templates and others, err... global variables.

    So let's say that you check if this is a global variable or template with an if statement with xor for errorchecking. Then you store this data in an array to be called upon later

    After all of this Then you do a preg_replace to replace all the {something}'s with data from the array.

    But what if you're using a function to call on the get templates function and you need the template to display some variables declared by the function? Since it's not a template, you can't get it from a global cache or mysql_query OR Global variable, since the variables are IN the function. how to you get these variables then?

    Sorry for the chaos above, but, this is what i could think of.

    And, how do you send $_GET/$_POST variables to another page via a log-in form. (e.g. for vB if you haven't logged in, the login message will be displayed. After logging in, you will get to the page you wanted to go to, with get variables all intact).


  • #2
    Maybe you would get more responses in the "PHP Coding" forum.


    • #3
      dont do it the way vB does, its very inneficient and server intensive.

      and i wudnt store them in database tables, becoz then u will have to preg_replace the variables.

      The best way is to just use functions, such as this:

      function wotever(){
      global $vars;

      return <<<EOF

      blah <html> wotever




      • #4 - Smarty, possibly the best templating solution I've used yet. Really cant sing its praises enough, anyway, take a lookski at it, might be just what ya after


        • #5
          ok, but right now my main question :

          How actually does it work?

          I've seen the code a bit, but don't really understand it (i'm a beginner @ php)

          i know that gettemplate() gets the template from the database, but how does it parse the template. (e.g. {imagesurl} and stuff, which may be other templates or variables)


          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.