Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Add PHP to your Templates (Trick)
TheAdminMarket's Avatar
TheAdminMarket
Join Date: Jun 2013
Posts: 511

 

Thessaloniki, Greece
Show Printable Version Email this Page Subscription
TheAdminMarket TheAdminMarket is offline 10-01-2014, 10:00 PM

First of all, let's make clear something. Yes, (unfortunatelly) vBulletin does not allows PHP in templates. But don't stuck on this. Extend your imagination. "If you can't go left, go right. Just don't stand"

The solution for this problem is much more easier than you can think. "If you can't add PHP in the templates, add templates to PHP" You just need a "echo" command in your PHP file. Yes it's so simple, the result will be exactly what you want, and most important, you can use vboptions, vbphrases, datamanager and everything you want.

1.- Create a template for Header:

HTML Code:
<template name="php_header" templatetype="template" date="" username="" version="">
<![CDATA[
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
    <title>Your Title</title>
    {vb:raw headinclude}
     <vb:if condition="$vboptions['storecssasfile']">
        {vb:cssfile forumhome.css, options.css, vbcms.css, widgets.css, sidebar.css, forumhome-rollup.css, usercp.css, additional.css}
    <vb:else />
        {vb:cssfile forumhome.css, options.css, vbcms.css, widgets.css, sidebar.css, forumhome-rollup.css, usercp.css, additional.css}
    </vb:if>    
</head>
<body>
{vb:raw header}
{vb:raw navbar}
<div class="blockbody">
]]></template>



Remark:
If you want to make use of vB sidebar in your page, you must add within head section:

HTML Code:
    <script type="text/javascript">
    <!--
        document.write('<script type="text/javascript" src="' + yuipath + '/animation/animation-min.js?v={vb:raw vboptions.simpleversion}"></script>');
        var sidebar_align = 'right';
        var content_container_margin = parseInt('{vb:math {vb:stylevar forum_sidebar_width}+{vb:math {vb:stylevar padding}*2}}');
        var sidebar_width = parseInt('{vb:stylevar forum_sidebar_width}');
    //-->
    </script>    
    <script type="text/javascript" src="{vb:raw vboptions.bburl}/clientscript/vbulletin-sidebar.js?v={vb:raw vboptions.simpleversion}"></script> 



2.- Create a template for Footer:


HTML Code:
<template name="php_footer" templatetype="template" date="" username="" version="">
<![CDATA[
</div>
{vb:raw footer}
</body>
</html>
]]></template>
3.- In your PHP file (assuming that is a file which loads all vB functions that you need), add (again is an example):

Code:
// Header Block
$templater = vB_Template::create('php_header');
$templater->register_page_templates();
$navbits = construct_navbits(array("my_php_file.php?" . $vbulletin->session->vars['sessionurl'] . ""=> "My Page"));
$navbar = render_navbar_template($navbits);
$templater->register('navbar', $navbar);
$header_block = $templater->render();
echo $header_block;
............Here you can add any PHP code that you like..............

Code:
// Footer Block
$templater = vB_Template::create(php_footer');
$templater->register_page_templates();
$footer_block = $templater->render();
echo $footer_block;
As you can see you can use ANY vB template in the PHP file. Just assign it to a variable and then use echo to show it in the screen.

Hope that this short tutorial will be useful to those who have stuck with this vB limitation. I love to use the Smarty template engine with PHP.
Reply With Quote
  #2  
Old 10-31-2014, 01:45 AM
abdobasha2004's Avatar
abdobasha2004 abdobasha2004 is offline
 
Join Date: Aug 2008
Posts: 541
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That is a way I searched for a lot!
Thanks Nick
Reply With Quote
  #3  
Old 10-31-2014, 07:45 AM
Linhnt Linhnt is offline
 
Join Date: Oct 2008
Posts: 7
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

For What?
Reply With Quote
  #4  
Old 10-31-2014, 07:47 AM
TheAdminMarket's Avatar
TheAdminMarket TheAdminMarket is offline
 
Join Date: Jun 2013
Location: Thessaloniki, Greece
Posts: 511
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Linhnt View Post
For What?
For what it needs? Just a word can explains it: AJAX
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:49 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06662 seconds
  • Memory Usage 2,240KB
  • Queries Executed 19 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (3)bbcode_html
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_box_bit
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (4)post_thanks_postbit_info
  • (3)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete