Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 08-26-2012, 06:11 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Keyword - Description Variable

I have a caresheet section that rests outside of vbulletin. It is integrated with vbulletin completely. I would like to be able to assign both keywords and a description within my caresheet.php files that are then used in place of the default vbulletin keywords and description I assigned for my website. I know I can use an if condition as described below to tell it when to use my keywords and description (tested - works) but I am trying to use a variable to assign the words themselves.

Code:
<vb:if condition="THIS_SCRIPT == 'careindex1' OR THIS_SCRIPT == 'careindex2'">
<meta name="keywords" content="{vb:raw mycarekeywords}" />
<meta name="description" content="{vb:raw mycaredescription}" />
</vb:if>
I would like to be able to set both the mycarekeywords and mycaredescription within the php file for each caresheet and have it used as the output but I am not succeeding and I think it is easier than what I have been trying. Any help would be appreciated. Thanks.
Reply With Quote
  #2  
Old 08-28-2012, 12:38 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I was hoping perhaps this wouldn't be that difficult to do. I could still use some help with this if anyone could steer me in the right direction.
Reply With Quote
  #3  
Old 08-28-2012, 01:10 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You would want to use register() or preRegister() to register the variables to the template. The difference is that register() needs to be called when the template is being rendered, where preRegister() can be called any time before. So it depends on how your code is set up. Assuming you're rendering your own template, you probably have something like:

Code:
$template = vB_Template::create('mytemplate');
// register variables here
$template->register('mycarekeywords', $mycarewords);
$template->register('mycaredescription', $mycaredescription);
print_output($template->render());

so you'd want to add those two middle lines.
Reply With Quote
  #4  
Old 08-28-2012, 02:58 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am using an independant template system apart from vbulletin. I am using vbulletins header and footer which includes the navbar, notifications, etc. I was hoping to set mycarekeywords as a variable like:

Code:
$mycarekeywords = 'my keywords here';
and then have those keywords used in place of the sites default keywords when headinclude is called.
Reply With Quote
  #5  
Old 08-28-2012, 04:05 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, then try this: create a plugin using hook parse_templates code like this:

Code:
if (THIS_SCRIPT == 'careindex1' OR THIS_SCRIPT == 'careindex2')
{
    $mycarekeywords = 'my keywords here';
    $mycaredescription = 'mycaredescription'; 
    vB_Template::preRegister('headinclude', array('mycarekeywords' => $mycarekeywords, 'mycaredescription' => $mycaredescription));
}
Reply With Quote
  #6  
Old 08-30-2012, 03:01 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Kevin and sorry for the delay in responding. That is how I am already doing it except directly in the headinclude template. Using the if condition I can simply assign the keywords in the template. I want to define the keywords and description in the file and have them passed over to the headinclude template as the file is called.

This would be the top of my PHP file:

Code:
<?php
define( 'THIS_SCRIPT', "templatetitle" );
$mycarekeywords = 'my keywords here';
$mycaredescription = 'my care description here';
Then when the file is called it pulls the data I entered as shown above and has that used as the output.
Reply With Quote
  #7  
Old 08-30-2012, 03:20 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, then take out where you set the variables and have it use globals instead, like:

Code:
if (THIS_SCRIPT == 'careindex1' OR THIS_SCRIPT == 'careindex2')
{
    global $mycarekeywords, $mycaredescription; 
    vB_Template::preRegister('headinclude', array('mycarekeywords' => $mycarekeywords, 'mycaredescription' => $mycaredescription));
}

and of course change the check of THIS_SCRIPT if you need to. Or you don't really have to have the if statement at all. In scripts other than your, the variables will be undefined and will appear blank.
Reply With Quote
  #8  
Old 08-30-2012, 08:01 PM
Rich's Avatar
Rich Rich is offline
 
Join Date: Mar 2004
Location: U.S.A
Posts: 921
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you very much Kevin! The globals worked wonderfully. I did omit the if condition within the plugin. I appreciate the help!
Reply With Quote
Reply

Thread Tools
Display Modes

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:06 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.04431 seconds
  • Memory Usage 2,226KB
  • 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
  • (6)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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