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)

Cheez-It 09-25-2006 04:37 PM

Do you need the first plugin as well when using that code Paul?

I'm actually trying to do this...

My goal is to have a template custom_header with a variable $custom_header which will contain all of the code from $header with a slight change (removing code for a right column and a different logo) for a CMPS home page...

1.) I do add new template, and put the code I want in it, saving it as custom_header. It now appears under "Custom Templates"

2.) I make a plugin with
Quote:

eval('$custom_header = "' . fetch_template('custom_header') . '";');
starting at global_start

3.) I add the plugin "globaltemplates[] = 'custom_header';" starting in cache template

I enable both.

I get error:Parse error: syntax error, unexpected '[' in /home/uninsta1/public_html/bu/forums/global.php(346) : eval()'d code on line 55

Right above the logo in ALL pages (not just CMPS...)

Shortly thereafter forums don't show and errors occur in functions.php as well.

I disable plugins.

What should I try next?

bitHacker 10-14-2006 10:41 AM

if you don't put $ before globaltemplates[], that won't work...

HPIA 10-31-2006 01:12 AM

Oh god, this is confusing. Is there any way of explaining this to someone illiterate in the technical coding world?

I want to incorporate my custom template into the forum and $mycustomtemplate isn't working.

Edit: Sorry for this post, I am an idiot. Worked it out. GREAT tutorial, this is EXACTLY what I was looking for ^_^

XXP 04-23-2007 01:07 PM

Quote:

Originally Posted by Kerry-Anne (Post 1018718)
... The easiest way to do this, although not technically the best,...

Thanks for this crucial and very helpful information. Should be in the vB manual!

A followup please: what exactly is "the technically best" way to do it?

Thanks.

puck916 04-26-2007 01:12 PM

I have this working completely, except in my hook I have $myvar = "test";

Now in my header template I have :
$myvar

Nothing happens. how can I get $myvar to be replaced with the dynamically created value from the hook?

iVox 06-08-2007 12:25 PM

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

jingman 08-13-2007 06:27 PM

Quote:

Originally Posted by iVox (Post 1264090)
In whatever template you wish...

The original post indicates that by attaching the "eval(.." plugin to the "parse_templates" hook, the template will be available to all other templates. I have not found that to be the case. I made a custom template, followed the above instructions precisely, and tried to use my custom template in FORUMDISPLAY and SHOWTHREAD - neither worked. It does work when I attach it to the "forumdisplay_complete" hook and the "showthread_complete" hook.

I want to be able to eval it in a single plugin, and make that template available to absolutely every other template - is there a way I can do that with a single hook?

loonytune15 12-09-2007 08:32 AM

This is just what i have been looking for. I now have my affiliates on a seperate template from my forum home :D

haaba 12-25-2007 10:04 PM

Like Jingman stated - none of your solutions working if new template is added to FORUMDISPLAY, no matter of the hook location...

Any other thoughts?

Thanks

GameWizard 01-04-2008 10:57 AM

Both Methods, original and that of iVox, seem to make my template appear, however they do not seem to parse the template. I have conditionals in my template, and they appear like ".(($post[field5]) ? (" on the page.

What can be done to fix this?


All times are GMT. The time now is 03:04 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.01106 seconds
  • Memory Usage 1,743KB
  • 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
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)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