vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Programming Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=188)
-   -   How To Include A Custom Template Via Plugins (https://vborg.vbsupport.ru/showthread.php?t=119933)

Omar Al-Ansari 08-04-2009 01:02 PM

Hi all,

I have tried this and it works good however it only works within vb if I try to use the same template in vba it does not?

any help will be appreciated

Product: vBulletin
Hook Location: global_start

Code:

eval('$adv_portal_rotating_articles = "' . fetch_template('adv_portal_rotating_articles') . '";');

ragtek 08-04-2009 01:04 PM

global_start is too early
try global_setup_complete instead

Omar Al-Ansari 08-04-2009 05:34 PM

Quote:

Originally Posted by ragtek (Post 1861194)
global_start is too early
try global_setup_complete instead

Hey ragtek,

Still not working

if i use this $adv_portal_rotating_articles in forumhome or any vb page it works fine

but not in vba

--------------- Added [DATE]1249411354[/DATE] at [TIME]1249411354[/TIME] ---------------

Quote:

Originally Posted by Omar Al-Ansari (Post 1861338)
Hey ragtek,

Still not working

if i use this $adv_portal_rotating_articles in forumhome or any vb page it works fine

but not in vba

ok nevermind I got it working .. :)

it should be defined through CMPS CP

ragtek 08-04-2009 05:52 PM

or also $GLOBALS[adv_portal_rotating_articles] should also work;)

Dax IX 10-12-2009 03:16 AM

Quote:

Originally Posted by iVox (Post 1264090)
Compliments to Kerry-Anne for posting this.

I'm new to vB, but a long time PHP guru and forum admin (including uBB and phpBB).

After reviewing some of the replies here I wish to add that the information presented here is not simply copy/paste, and requires basic knowledge of PHP as well as the hook and template system of vB. I noticed some of the more experienced PHP developers making suggestings and fixes here. I concur and wish to expand on that.

I tried the procedure, and with a few minor corrections got it to work with less overhead simply by optimizing the commands (using advice posted earlier plus new advice from me):

I can sum it up in 4 easy steps (vb 3.6.7+):

1) Create a custom template, i.e. "mytemplate" for purposes of these instructions

Put in there "Hello World!" or any HTML so you know its working when it displays.

2) Add a new plugin, suggested name is "mytemplate_plugin" for easy reference

Pick hook as "global_start" if you want your template available in any other, or select the appropriate hook depending on where you want your template to display. The latter is the better choice if you are customizing a specific feature of vB.

Set plugin PHP code: $mytemplate_plugin = fetch_template('mytemplate_plugin_home');

3) Create another plugin, suggested name is: "Cached - mytemplate_plugin"

Pick hook as "cache_template" (located within vBulletin; General hooks in pulldown)

Set plugin PHP code: $globaltemplates[]='mytemplate_plugin';

4) In whatever template you wish (based on step 2) place the variable $mytemplate_plugin where you want your custom template to display. If successful, you'll see your "Hello World!" or your HTML as in step 1.

Folks, that's all there is to it. Notice no need for eval or array_merge.

This approach follows a simple naming convention that's easy to understand long after you implement and forget, and uses the most efficient PHP to get the job done, and will work perfectly without have to hack any native vB code. Yes, there are a million ways to skin a cat, this is one, but if you start doing alot of customization of this type, keeping the naming convention and optimizing the PHP code will save valuable server resources.

Compliments to all who posted.

Thanks for your time and if I missed something, please let me know.

-jim

I'm a little confused. The code in this post makes very little sense to me. Is it still valid?

Quote:

Originally Posted by IdanB (Post 1828222)
2 plugins:
1] location: "global_start"
name: "alt_lp_template"
with followign code:
PHP Code:

$alt_lp_template fetch_template('alternate_view'); 

2] location: "cache_templates"
name: "Tempalte Cache"
with followign code:
PHP Code:

$globaltemplates[] = 'alt_lp_template'

and on forum i keep getting "uncached template" warning for "alternate_view".
Note this template was added to master style.

EDIT: what's more weird, i know it's cached, as later on i can access it from $vbulletin->templatecache['alternate_view']

Quote:

Originally Posted by ragtek (Post 1828230)
You have to make it this way:
to cache it:
PHP Code:

 $globaltemplates[] = 'alternate_view'

and save the content from the template into a variable:
PHP Code:

eval('$varname = "' fetch_template('alternate_view') . '";'); 

Now you can use $varname

Quote:

Originally Posted by IdanB (Post 1828249)
thanks, that solved it, wrote under cache name the var name instead... silly me :p

Can you explain exactly what you did to fix this? Did you still need the eval() code?

I can get the contents of my test template to show, but it escapes my quotes within my HTML, so no styling is applied. :(

--------------- Added 12 Oct 2009 at 12:11 ---------------

Here's the code that I used:

2 plugins:
1] location: "global_start"
name: "test_template_plugin"
with followign code:
PHP Code:

$test_template fetch_template('test_template'); 

2] location: "cache_templates"
name: "Cached - test_template"
with followign code:
PHP Code:

$globaltemplates[]='test_template'

Like I said, I can see my content, but quotes are escaped, so no styling is applied.

my template contents (test_template) (VERY simple)

HTML Code:

<table class="test_template_table">
    <tr>
        <td class="test_template_td">
            Hi there!
        </td>
    </tr>
</table>

What am I doing wrong?

--------------- Added [DATE]1255400076[/DATE] at [TIME]1255400076[/TIME] ---------------

I was trying to follow the advice of the first post that I quoted, and it just didn't work.

I changed the first plugin to include the eval() code for my variable, and it worked properly. :)

Sorry for the bother. :)

Assopoker 12-15-2010 06:52 PM

This is a best way to add a template to a product in vb4?

EquinoxWorld 07-08-2011 01:38 PM

Also would like to know if this article is still valid? Anyone can provide us with some confirmation please.

BirdOPrey5 07-08-2011 02:43 PM

No this is only valid for the 3.x series of vBulletin. Check the VB 4.x Articles section for more relevant articles.

TTayfun 10-27-2011 09:44 AM

but why not working in STANDARD_REDIRECT template ? how can i do?

BlueChipEarth 08-07-2012 07:38 PM

I have tried everything you have provided to the very letter, and it simply doesn't work at all... the variable is always null when I call for it in the template.

I'm trying to add a custom template to the forumhome_forumbit_level1_post template.

What am I doing wrong!?

Here's how I have it set up:

New Custom Template - title is: sponsorForumButtons

Right now I just have it filled with "TESTING THE NEW TEMPLATE"

I have added a new Plugin, which is active, in global_start (I've tried in forumdisplay_complete, forumdisplay_start, global_complete, all the forumhome hooks... I've tried every single hook location I could think of... none seem to work)

This is the exact code of the Plugin:

//Sponsor Forum Buttons

eval('$sponsorForumButtons = "' . fetch_template('sponsorForumButtons') . '";');

Then in the forumhome_forumbit_level1_post template I have:

$sponsorForumButtons

Right where I want it to show up.

No matter what I try the variable just doesn't show up... even if I EXPLICITLY set the variable in the forumdisplay_start (or any other) hook... shouldn't the global_complete hook be available to every template!? Even so, how is it that the variable is ALWAYS null? It seems like the variable will show up in the FORUMDISPLAY template, but if I put it into the forumhome_forumbit_level1_post template, the variable is inexplicably null.

I have even tried to cache the template in cache_templates and parse_templates. That code looks like this:

$globaltemplates[]='sponsorForumButtons';

NOTHING WORKS!

I am having a nervous breakdown. Please save me from killing myself...


All times are GMT. The time now is 09:55 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.02192 seconds
  • Memory Usage 1,763KB
  • 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
  • (1)bbcode_code_printable
  • (1)bbcode_html_printable
  • (6)bbcode_php_printable
  • (6)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete