SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: gettemplate

  1. #1
    Non-Member MrLister's Avatar
    Join Date
    Feb 2001
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    gettemplate

    hehe me again. i'm still trying to study vB so I can make my own addons and everything but i'm really stuck on this one. i'm not sure how this works exactly. i read php.net and understand how and what eval(); does but this one is a lot different.

    eval("\$pminfo = \"".gettemplate('forumhome_pmloggedin')."\";");

    a normal one that i'd probably use is
    eval("\$something = \"$anotherone\";");

    A few of my questions:

    1. Where is the ".gettemplate('forumhome_pmloggedin')." function in vB. (which file)?
    2. How does this .gettemplate thing work?
    3. If I were to make one from scratch what would i need in order to accomplish this?

    Thank You for your time and your help is greatly appriciated to this newb trying to learn PHP.

  2. #2
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In vBulletin, gettemplate is located in functions.php in the admin directory.
    Basically what it does is check the template cache for the template called, and if it doesn't find it, it pulls the template directly from the database.

    Not quite sure what you mean make it from scratch, but if you are talking about how to call a template like that, you just substitute your variable and what template you want it to call. Then put the variable somewhere in the code or the templates.
    Kevin

  3. #3
    Non-Member MrLister's Avatar
    Join Date
    Feb 2001
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the help and i have just one more. how can i make a script similar to this that will just pull it out of the database?

  4. #4
    Non-Member MrLister's Avatar
    Join Date
    Feb 2001
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i think i got it. correct me if i'm wrong
    PHP Code:
    function gettemplate($templatename,$escape=1,$gethtmlcomments=1) {
      
    // gets a template from the db or from the local cache
      
    global $templatecache,$DB_site,$templatesetid,$addtemplatename;

        
    $gettemp=$DB_site->query_first("SELECT template FROM template WHERE title='".addslashes($templatename)."' AND (templatesetid=-1 OR templatesetid='$templatesetid') ORDER BY templatesetid DESC LIMIT 1");
        
    $template=$gettemp[template];
        
    $templatecache[$templatename]=$template;

      if (
    $escape==1) {
        
    $template=addslashes($template);
        
    $template=str_replace("\\'","'",$template);
      }
      if (
    $gethtmlcomments and $addtemplatename) {
        return 
    "<!-- BEGIN TEMPLATE: $templatename -->\n$template\n<!-- END TEMPLATE: $templatename -->";
      }

      return 
    $template;

    So if i put this in a file called temps.php and in global.php i do require("./temps.php"); and i have a persistant connection there. i should be able to do
    PHP Code:
    eval("\$pminfo = \"".gettemplate('forumhome_pmloggedin')."\";"); 
    as long as in the database i have a row called template and all the values in it like vB.

  5. #5
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes that should work.
    Kevin


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
  •