vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Writing my first plug-in/product, several newbie questions. (https://vborg.vbsupport.ru/showthread.php?t=120369)

Paul M 07-07-2006 03:49 AM

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';


:)

Kirk Y 07-07-2006 09:46 AM

Well, I learned something new too then, thanks Paul. When should array merge be used?

Guest210212002 07-08-2006 11:41 AM

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 :D
- 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. :D

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!)

Kirk Y 07-08-2006 02:00 PM

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.


All times are GMT. The time now is 02:02 AM.

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.01817 seconds
  • Memory Usage 1,736KB
  • 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
  • (4)bbcode_code_printable
  • (1)bbcode_php_printable
  • (3)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
  • (4)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