vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   PhP functions with params in Templates (https://vborg.vbsupport.ru/showthread.php?t=193013)

temporaryins 10-07-2008 10:42 PM

PhP functions with params in Templates
 
I'm trying to do a pretty simple set of functions. I have a seperate custom_functions.php page I've included in my template page and now I need to call a function from that in the template and use it to print out some XHTML markup with another template called as a param in the function. The function looks like:

Code:

function graphicSection ($content) {
echo('<div>');
echo($content);
echo('</div>');
}

I want to call it in the template file as:

Code:

graphicSection($othertemplatevariable)
I don't care how the code looks really. I'd just like to be able to pass a template in as a parameter and have it print it all out. Is this even possible? What documentation do I need to look through to do this. I've looked over a lot of posts here and in the manual and can't quite find the procedures that tell me how to do this.

Marco van Herwaarden 10-08-2008 07:41 AM

You can not make a PHP call in templates (with the exeption of a few predefined ones).

vbplusme 10-08-2008 10:58 AM

If you were more clear about your project, you might get a better answer but from what you have provided, you need to be thinking plugin to use php code in templates.

PHP Code:

eval('$special_event_notice = "' fetch_template('special_event_notice'). '";'); 

Once you have created this plugin, you can use the variable $special_event_notice pretty much anywhere and it will display the content of the template.

But the question you are asking goes a little deeper than just calling a template.

PHP code needs to be added to a plugin in order to use it and some of the PHP calls can not be used, like echo. For example, you can not use :

PHP Code:

echo " this is what I want to display"

But you CAN use:

PHP Code:

$displayme "this is what I want to display" 

and just place the variable name where you want it to display in your template or any of the other vBulletin templates for that matter depending on what hooks you use.

HTH


All times are GMT. The time now is 12:36 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.01047 seconds
  • Memory Usage 1,715KB
  • 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_code_printable
  • (3)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