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

Reply
 
Thread Tools Display Modes
  #11  
Old 07-07-2006, 04:49 AM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by harmor19
Why can't you use a simple variable instead of those functions
I would guess because he wants to learn how to use templates.

Quote:
Originally Posted by acidburn0520
Try this code in a plugin using hook 'cache_templates':

Code:
if (THIS_SCRIPT == 'index'){
	$globaltemplates  = array_merge($globaltemplates, array('silly_newbie_template'));
}
Array merge is overkill for this, just add to the array.

PHP Code:
if (THIS_SCRIPT == 'index')
{
    
$globaltemplates[]  = 'silly_newbie_template';

Reply With Quote
  #12  
Old 07-07-2006, 10:46 AM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I learned something new too then, thanks Paul. When should array merge be used?
Reply With Quote
  #13  
Old 07-08-2006, 12:41 PM
Guest210212002
Guest
 
Posts: n/a
Default

Once again thank you all very, very much for guiding me through this.

Here's what I changed:

- Dropped the executionorder per acidburn's advice
- Made the template phrased because I forgot to the first time
- Removed the search string from the template because I know how it works now (thank you again, acidburn)
- Added Paul's code snippet to add to the global template array
- Added JumpD's code to grab the template from cache
- Changed the hook to forumhome_complete

Things I'm not sure on:

- What/how the template actually gets added to the global templates, unless that's exactly what Paul's code does. I'm assuming that it's basically if you're on the index, then add s_n_t to the cache?
- If I took a step forward here.

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="chris777_showinvisible" active="1">
<title>Show Invisible Users Online</title>
<description>Will add a count of invisible users in WGO.</description>
<version>1.0.0</version>
<dependencies></dependencies>
<codes></codes>
	<templates>
		<template name="silly_newbie_template" templatetype="template" username="chris-777" version="1.0.0">
		<![CDATA[
		<!-- Newbie Template -->
		<phrase>$vbphrase[online_invisible]</phrase> $numberinvisible  
		<!-- /Newbie -->
		]]>
		</template>
	</templates>
<plugins>
	<plugin active="1">
		<title>Show Invisible in WOL</title>
			<hookname>forumhome_complete</hookname>
			<phpcode><![CDATA[
				if (THIS_SCRIPT == 'index') 
				{ 
				    $globaltemplates[]  = 'silly_newbie_template'; 
				}  
			$search_text = '$vbphrase[x_members_and_y_guests]</phrase>)';
			$vbulletin->templatecache['FORUMHOME'] = str_replace($search_text,												$search_text.$vbulletin->templatecache['silly_newbie_template'],$vbulletin->templatecache['FORUMHOME']); ]]>
			</phpcode>
		<phrases>
		<phrasetype name="GLOBAL" fieldname="global">
			<phrase name="online_invisible">
			 <![CDATA[ Invisible:  ]]> 
			</phrase>
		</phrasetype>
	</phrases>
</product>
Again, very much appreciated. My weekend plan is to get this all sorted out. (Quite the party, I know!)
Reply With Quote
  #14  
Old 07-08-2006, 03:00 PM
Kirk Y's Avatar
Kirk Y Kirk Y is offline
 
Join Date: Apr 2005
Location: Tallahassee, Florida
Posts: 2,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You don't need the <phrase> tags around $vbphrase[onlineinvisible]. You'll only need those if you're going to be using a variable inside of the phrase. For example: phrase1: "There have been {1} users online today, but there were {2} online yesterday." Then you'd use: <phrase 1="$userstoday" 2="$usersyesterday">$vbphrase[onlinetoday]</phrase>.

Paul's code caches the template so your board doesn't have to query for it every page load. The template is installed (if that's what you were trying to say) whenever the product is imported.

This code needs to be put in a plugin by itself using hook 'cache_templates'.
Code:
if (THIS_SCRIPT == 'index') 
				{ 
				    $globaltemplates[]  = 'silly_newbie_template'; 
				}
You'll want to take a look at this code again too, as it looks like you didn't copy the whole code that was posted. Take another look at JumpD's post.
Code:
$search_text = '$vbphrase[x_members_and_y_guests]</phrase>)';
			$vbulletin->templatecache['FORUMHOME'] = str_replace($search_text,
Quote:
- Removed the search string from the template because I know how it works now (thank you again, acidburn)
If you remove the search string from the template, the plugin won't know where to place the 's_n_t' code. As I said earlier, the search string is not replaced, instead whatever is in the 's_n_t' template is added beneath it.
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 09:43 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.06765 seconds
  • Memory Usage 2,204KB
  • 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_code
  • (1)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (3)postbit_onlinestatus
  • (4)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete