vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How to change a variable value INSIDE of a template based on condition (test)? (https://vborg.vbsupport.ru/showthread.php?t=100597)

timetunnel 11-11-2005 04:48 PM

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.

Marco van Herwaarden 11-11-2005 06:17 PM

Templates are HTML, not PHP. You can not run PHP inside templates.

timetunnel 11-11-2005 06:31 PM

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!


All times are GMT. The time now is 03:14 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.01602 seconds
  • Memory Usage 1,722KB
  • 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
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete