PDA

View Full Version : Pass variable from Template to PHP


neof
12-27-2008, 01:53 PM
I'm using 3.6.8. I want to include my own php code into the FORUMDISPLAY template after
<body>
$header
$navbar
<-------------insert my code here

1) How do I pass the variable like $foruminfo[title] from the templates into the PHP file?
The php file will process the $foruminfo[title] value and the result is inserted back into FORUMDISPLAY template.

Marco van Herwaarden
12-27-2008, 02:04 PM
You don't pass those variables like that from a template to a PHP script. They are passed from a PHP script to the template.

neof
12-27-2008, 03:01 PM
Thanks I need to know the user's current pages' info such as Forum Title, so I am guessing that I have to get the info from the template, because the external php script don't know what page the user is on. I think I get the info from the template, pass it to the php file, and the result of the php file is passed back into template to display to user. Pls let me know if there is other method to process the forumtitle for each user.

Marco van Herwaarden
12-27-2008, 03:04 PM
What are you trying to accomplish?

Sounds to me like you are overcomplicating things and trying to write unneeded coding.

Lynne
12-27-2008, 03:22 PM
How are you calling the script? From a plugin? If so, the information you are wanting is most likely all ready available to you. Perhaps if you are a bit more specific here, we can help you out better.

neof
12-27-2008, 03:44 PM
when a user visits any forum page, I want to extract the forumtitle on that page and pass it to a phpscript which will insert the forumtitle into an api to an external searchengine. That searchengine will return some results back to the phpscript, and I need to display that result back to the user on his current page. Example: As soon as a User visits any forum page (assume a page's title is called "games"). I need to extract "games" and send that to the searchengine which returns "arcade game, video games, flash games, etc" which I need to display "arcade game, video games, flash games, etc" back to the user on whatever the page that just loaded for the user.

Marco van Herwaarden
12-27-2008, 03:52 PM
Is the communication with the search engine asynchronous?

neof
12-27-2008, 08:47 PM
I think yes it is asynchronous because we don't know when the users visit the pages or which page. as soon as the page loads, the forumtitle is extracted, passed to php, passed to api which returns the results to php, and passed back to the loaded page to show the info to the user. pls let me know if there is a better way

Dismounted
12-28-2008, 03:13 AM
Can you wait for the external script to return results, or is it too slow to return data?

neof
12-28-2008, 05:32 AM
I'm not worried about the speed of the external php script since the returned results is instant. How do I pass the forumtitle of the loaded page to that php script, and pass the result back to the loaded page?

Marco van Herwaarden
12-28-2008, 07:35 AM
If the script waits until the external script returns the information, then it is synchronous.

All you need to do is create a plugin that will call the externalscript and use the values returned to create the page output.