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 11-11-2005, 04:48 PM
timetunnel timetunnel is offline
 
Join Date: Sep 2005
Posts: 86
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to change a variable value INSIDE of a template based on condition (test)?

Hello.

How to change the value of a php file var WITHIN a template?

I'm still trying to understand this vB system.

Example:

For FAQ search, I want to change the default value of 'Matching Options' on-the-fly from 'ALL' to 'ANY' via the template and NOT by hacking faq.php.

For example, I created this via the Plugin Manager in hook location, 'faq_start':

PHP Code:
if ($_SERVER['QUERY_STRING'] == "") {
  
// print "QUERY IS MT";
  
$new_default 'selected="selected"';
  
$matchselect['all'] = "";
  
$matchselect['any'] = $new_default;

I'd like this to be executed INSIDE the FAQ template just prior to the search form being displayed (and before a query string is constructed) so that the default values will be the changed values.

How can I call this code WITHIN the template?

It would be ideal (at least until I understand the 'hook' system better) to call this via "($hook = vBulletinHook::fetch_hook('match_default')) ? eval($hook) : false;" directly inside of the template at the appropriate location OR some other way, which I have no idea... :ermm:

Any suggestions on how to accomplish this end result?

Thanks in advance.
Reply With Quote
  #2  
Old 11-11-2005, 06:17 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Templates are HTML, not PHP. You can not run PHP inside templates.
Reply With Quote
  #3  
Old 11-11-2005, 06:31 PM
timetunnel timetunnel is offline
 
Join Date: Sep 2005
Posts: 86
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for your reply.

I know that you can't write PHP code inside of templates which is why I was trying to find another solution by creating the custom 'plugin'. I just didn't know how to get the vB software to recognize/execute it in the proper location. But, now I've since found out...whew.

I FOUND IT! FINALLY......I think I know how the 'hook' system works!

I had to read this thread again: https://vborg.vbsupport.ru/showthread.php?t=82625 and it finally 'clicked' on post# 28 ("...so the closest hook i could find is this...).

I needed to add my custom code, NOT to faq_start hook, but to faq_complete since it was a hook that came AFTER the code I needed in faq.php!!!! So that's what a hook is!!! :lick:


PHP Code:
if ($_SERVER['QUERY_STRING'] == "") {
  
// print "QUERY IS MT";
  
$new_default 'selected="selected"';
  
$matchselect['all'] = "";
  
$matchselect['any'] = $new_default;
  
$matchselect['phr'] = "";

I can now use this code as a pseudo 'Control Panel'. If in the future I want to change the default, I'll just change it in 'Plugin Manager' in my custom 'plugin'!

Now, I'll be able to search php files for existing hooks and then create plugins to fit in the appropriate hook. If none exist in the right location, then I'll probably have to hack the file. I hope this process is correct for this is how I understand it now.

Thanks to vb...org and its members for the 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 12:49 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.03412 seconds
  • Memory Usage 2,180KB
  • Queries Executed 11 (?)
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
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)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_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