No announcement yet.

Using custom templates within your own vBulletin 4 based files

    David IB
    New Member

  • Using custom templates within your own vBulletin 4 based files

    <style type="text/css"> <!-- @page { margin: 0.79in } P { margin-bottom: 0.08in } --> </style> Custom Templates
    If you create custom vBulletin based files that utilize custom created templates within your forum installation, there are a few tricks to get them to work with vBulletin 4. Prior to vBulletin 4, you were able to use the following code to get vBulletin to evaluate the custom template for your script.

    eval('print_output("' . fetch_template('myCustomTemplate') . '");');

    With vBulletin 4, the same thing can be accomplished with the following two lines of code.

    $templater = vB_Template::create('myCustomTemplate');

    This code will now allow you to reference vBulletin 4 functionality to use your custom template within your custom vBulletin PHP file.

    Imagine that your
    custom vBulletin PHP script simply outputs the words "Hello there" and you want that text to appear within your own custom vBulletin template. Your file would have the following somewhere within the code.

    $myScript_variable = "Hello there";

    Within your custom template (called
    myCustomTemplate as an example), you would reference this variable as follows.

    {vb:raw myScript_variable}

    Back within your script, you can make a call to force your custom template to be evaluated. This would be accomplished using the previously example.

    $templater = vB_Template::create('myCustomTemplate');

    • voomies
      Senior Member
      voomies commented
      Editing a comment
      I tried to upload a graphic saved on my computer as bbtitle2.xml, but I keep getting this message: No file uploaded and no local file found. Any ideas? The file is right there under the Import Style XML function but it isn't getting picked up. HELP!!

    • TWTCommish
      Senior Member
      TWTCommish commented
      Editing a comment
      I assume we can we use the first line of code once, and then call $templater throughout the script later on?

    • tounet
      New Member
      tounet commented
      Editing a comment
      I have a php file inspire the product "Rate My Photo (HorOrNot Clone)" and correctly displays the best picture of my database and uses a template but I am unable to make my block:

      the php code

      PHP Code:

      global $vbulletin
      // Include Globals 

      $bestphoto =$vbulletin->db->query_first("SELECT * FROM vb_ratemyphoto_photos WHERE approved=1 AND hidden=0  

      AND rating>0 ORDER BY rating DESC, votes DESC LIMIT 1"
      $besttitle htmlspecialchars_uni($bestphoto["title"]); 
      $bestphotoname $bestphoto["logo"]; 
      $bestvotes $bestphoto["votes"]; 
      $bestrating $bestphoto["rating"]; 
      $templater vB_Template::create('block-photo'); 

      the template :

      HTML Code:
      <li>    <div class="block smaller">       
       <div class="blocksubhead">        Meilleur photo            </div>        
      <div id="block_title" class="blockbody floatcontainer" {vb:raw}>            
      <div class="blockrow">
      <img src="../forum/ratemyphoto/photo/thumbs/{vb:raw bestphotoname}" alt="" />
      <div class="underblock"></div></li>

      please where is the error
    Posting comments is disabled.

Related Topics