Announcement

Collapse
No announcement yet.

Template function like vbulletins

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Template function like vbulletins

    I am recoding my website and am changing the way it handles its templates, I want it to be more like vbulletins.

    I have the templates in a database. When the user comes to the site it gets the vbulletin cookie, if it exists it validates the user, gets their vbulletin style template option and gets some options from a non-forum table, These are basic options to do with my site.

    It then processes all the page data (its a gaming site, so say a certain guide), calls a function called temp_parse() which is like a cut down version of vbulletins template parser and displays the page.

    I wont go into all the template selection (multiple site styles) as that works perfectly and doesnt affect my problem.

    Heres my temp_parse() function:

    PHP Code:
      function temp_parse($templatename$styleid)
      {
         global 
    $templatecache$styleid$db_site;
      
         if (
    $templatecache[$templatename]!="")
         {
            
    $template $templatecache[$templatename];
         }
         else
         {
            
    // We get the template from the database
          
    $result mysql_query("SELECT body FROM $db_site.rg6_template WHERE name='$templatename' AND styleid = '$styleid'");
      
            if (
    mysql_num_rows($result) > 0)
            {
               while(
    $row mysql_fetch_object($result))
               {
                  
    // get the db field
                  
    $template $row->body;
      
                 
    // replace \" with \\" ... this will be needed later in the script
                  
    $template str_replace("\"","\\\"",$template);
      
                  
    // cache the contents
                  
    $templatecache[$name] = $template;
                }
             }
             else
             {
                
    $template="$template";
             }
         }
      
      
         return 
    $template;
      } 
    Simple enough as you can see. Its called using an eval, which can either call the template and store the result in a variable, or echo it directly to the screen, again, similar to vbulletin.

    The main thing I want to add to it, is the conditionals that vbulletin uses, mainly for changing display elements dependant upon the user being a logged in member or a guest. Theres a few other things too.

    I used to do this by having IF statements in my main PHP code that would parse different templates. Instead I want to have ONE template, but have IF statements in the template that would have the same effect as the old way (just cleaner and more efficient).

    I would also like to have the conditionals formatted and function the same way as vbulletin does, as my sites template designers get on well with it that way.

    Can anyone help me here?

    I have looked for the function in vbulletin but cant find it for the life of me, plus I would imagine it couldnt be "lifted and called" as is, as it would need adapting.

    So, coding my own function to so this would seem to be the way to go.

    Thanks in advance to anyone who can help me with this one.

    Also, I cant use a 3rd party template engine that has this functionality as the site is part of an academic project, so using something like smarty would detriment my grade.
    Last edited by RGSerge; Fri 28th Nov '03, 2:50pm.

  • #2
    Nobody able to help me with this?

    Comment


    • #3
      you could use smarty.php.net ...

      Comment

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