Quote:
Originally Posted by iVox
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
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
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
thanks, that solved it, wrote under cache name the var name instead... silly me 
|
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.