vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   Add PHP to your Templates (Trick) (https://vborg.vbsupport.ru/showthread.php?t=314677)

TheAdminMarket 10-01-2014 10:00 PM

Add PHP to your Templates (Trick)
 
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.

abdobasha2004 10-31-2014 01:45 AM

That is a way I searched for a lot!
Thanks Nick

Linhnt 10-31-2014 07:45 AM

For What?

TheAdminMarket 10-31-2014 07:47 AM

Quote:

Originally Posted by Linhnt (Post 2520721)
For What?

For what it needs? Just a word can explains it: AJAX


All times are GMT. The time now is 02:22 PM.

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.01093 seconds
  • Memory Usage 1,727KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (3)bbcode_html_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete