Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-07-2006, 05:11 PM
tgreer tgreer is offline
 
Join Date: Oct 2005
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Custom Templates

Two questions:

1) How do you include a custom template within a product, so that when the product is installed, the template is created?

2) What is the mechanism to "swap" a default template with a custom template via a product/plugin?

I realize that question number 2 is likely very involved, so I'll provide some of my guesses and you can correct me where I'm wrong:

Use the "cache_templates" hook, creating a plugin there. That plugin will check to see if the product is installed/enabled, and if so, will somehow replace the original template with the "product" template. Am I on the right track?

By "replace", I don't mean physically - I'm not trying to erase any default templates. In fact, I want to avoid altering any templates at all. If my product is installed, I want vBulletin to USE a custom template instead of an exisiting standard template.

TIA.

Automerged Post:

What I've decided to do:

Hook: cache_templates

PHP Code:
global $globaltemplates;

$globaltemplates  array_merge($globaltemplates, array('myTemplate')); 
Hook: global_start

PHP Code:
$vbulletin->templatecache['defaultTemplate'] = $vbulletin->templatecache['myTemplate']; 
My question still remains on how to package a custom template in an install file. Is there a tutorial on building install/product files?

Also, I'm receptive to discussion/feedback. Is this the best approach to swapping templates? Could str_replace be used instead, if so, how?
Reply With Quote
  #2  
Old 04-07-2006, 08:15 PM
hambil's Avatar
hambil hambil is offline
 
Join Date: Jun 2004
Location: Seattle
Posts: 1,719
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by tgreer
Two questions:

1) How do you include a custom template within a product, so that when the product is installed, the template is created?

2) What is the mechanism to "swap" a default template with a custom template via a product/plugin?

I realize that question number 2 is likely very involved, so I'll provide some of my guesses and you can correct me where I'm wrong:

Use the "cache_templates" hook, creating a plugin there. That plugin will check to see if the product is installed/enabled, and if so, will somehow replace the original template with the "product" template. Am I on the right track?

By "replace", I don't mean physically - I'm not trying to erase any default templates. In fact, I want to avoid altering any templates at all. If my product is installed, I want vBulletin to USE a custom template instead of an exisiting standard template.

TIA.

Automerged Post:

What I've decided to do:

Hook: cache_templates

PHP Code:
global $globaltemplates;

$globaltemplates  array_merge($globaltemplates, array('myTemplate')); 
Hook: global_start

PHP Code:
$vbulletin->templatecache['defaultTemplate'] = $vbulletin->templatecache['myTemplate']; 
My question still remains on how to package a custom template in an install file. Is there a tutorial on building install/product files?

Also, I'm receptive to discussion/feedback. Is this the best approach to swapping templates? Could str_replace be used instead, if so, how?
Hmmm. Well, a couple of things.
First, create a new empty product in the admin cp.
Then use the admin cp to create any templates, plugins, and phrases you want for your hack. You can also put install code into the product via the admin cp (look at editing your product).
The only thing you can't do is create new admin cp options this way. The best advice on that is to look at how someone else has already done it, since it's a common thing fancier hacks need to do.
Once you've got all your templates and such created in the admin cp (make sure they are all marked as belonging to your product) then you just export the product. It will automatically create the xml file for you.

As for modifying templates, I'm not sure I understand your need. There are two ways I tend to modify a template on the fly. One is to simply add to the output before it goes to the template, such as I discuss in this thread, the other is similar to what you are doing, only I use a replace to modify some part of the template rather than replacing the entire template.

Replacing an entire template seems problematic to me, as it would mean other peoples hacks written to work on that template would no longer work.
Reply With Quote
  #3  
Old 04-07-2006, 08:27 PM
tgreer tgreer is offline
 
Join Date: Oct 2005
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks. Ok, I understand now how to create products, including phrases, plugins, and templates.

Good point about replacing entire templates. My goal is to not edit or require the user to edit, any templates, ever, in terms of adding a plugin/product.

So you use str_replace, then, to only modify portions of the template? Agreed, that's a better idea.
Reply With Quote
  #4  
Old 04-07-2006, 08:34 PM
hambil's Avatar
hambil hambil is offline
 
Join Date: Jun 2004
Location: Seattle
Posts: 1,719
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by tgreer
Thanks. Ok, I understand now how to create products, including phrases, plugins, and templates.
This also allows you to look at the xml it produces, and start to understand it better becuase you can match it to what you know you did.

Quote:
Originally Posted by tgreer
Good point about replacing entire templates. My goal is to not edit or require the user to edit, any templates, ever, in terms of adding a plugin/product.
We share that goal.

Quote:
Originally Posted by tgreer
So you use str_replace, then, to only modify portions of the template? Agreed, that's a better idea.
Yes. The less intrusive you can be the better.
Reply With Quote
  #5  
Old 04-07-2006, 09:45 PM
tgreer tgreer is offline
 
Join Date: Oct 2005
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

For this particular project, the original template should show if the user is registered, and a completely different table if they are a guest.

SO, I still added a new custom template and did the complete template swap. Why? The user should still have the ability to customize my table, as with any other template.

However, in the <else /> clause, instead of a copy of some original version of the template, I have $GLOBALS[$orig_template]. My plugin, prior to swapping templates, evaluates $orig_template to the users current version.

Best of both words: I don't stomp all over their template changes, but I give them another template to edit to modify my plugin's appearance.

Thanks for your help.
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 07:00 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04396 seconds
  • Memory Usage 2,217KB
  • Queries Executed 13 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • 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