![]() |
PHP API code in template, php file, or somewhere else?
I have the following PHP code:
Code:
<? |
You will need to create a plugin at the appropriate location as you cannot run PHP code in templates directly.
|
This will need to be called many times with different settings. Do I need a seperate plugin for each call ($359api_chars, $359api_tree, etc) or can the plugin be used as an array? I followed the instructions from https://vborg.vbsupport.ru/showthrea...ghlight=plugin, but when I put $359eveit[1][charname] in the display template, it actually shows the variable name, rather than nothing. Considering it should be a blank variable, it should display nothing, right?
|
PHP variable names cannot begin with a number.
|
Thank you, having all these problems and never thought of that :)
Alright, I've changed everything around so it is now $eveit359. Plugin output is now getting to the template, as long as it's plain HTML. When I try to make $eveit359 into an array (store a value into $eveit359[1], and put that in the template, I get output like "p[charname]". I am completely lost trying to figure out what the heck the template/plugin tutorials are saying with variable renaming or whatever it is they're talking about. I need to have several arrays of data accessible to the template, preferably in one big array $eveit359[1][charname], $eveit359[1][charid], $eveit359[1][tree][current], $eveit359[1][tree][time], etc. |
I don't know might be something to do with your script. Arrays start from 0 not 1. I don't know why you are storing it in arrays you can store it as a variable normally. If it makes it easier to use arrays then use arrays. If you have multidimension arrays consider surrounding it in brackets. Like in your template have:
PHP Code:
PHP Code:
|
My current plugin template content:
PHP Code:
I tried changing the plugin template to a simple PHP Code:
PHP Code:
Not sure if what you meant was to use another variable in the plugin and display templates, but I tried PHP Code:
Could the Api functions be causing a problem? The plain text script output starts with "debug(false); $api359->cache(true);" as if that first "->" is a problem. --------------- Added [DATE]1200517434[/DATE] at [TIME]1200517434[/TIME] --------------- I just tried PHP Code:
HTML Code:
<?php If I change the double quotes to single quotes, output is blank. |
You don't need to have <?php and ?> in plugins, as the code is evaluated (using eval()).
|
New plugin template:
PHP Code:
Code:
require_once('./eveitapi/class.api.php'); require_once('./eveitapi/class.charselect.php'); = new Api(); (false); // enable debugging (false); // do not use a cache-file, if one exists (1188020,RDQiA46jtGtzMUEFVtgbtJ2CfhTCIPGkD0JeUz22NomPeQWCx552fwe0gwkSi4bh); = (); = CharSelect::getCharacters(); = [charname]; = "Hello"; echo "Hello"; The above is using the "eval" plugin and "array_merge" cache plugin. When I use the method from this post I get the following output. Still doesn't parse it, but at least this way it's not evaluating the variables. Code:
require_once('./eveitapi/class.api.php'); require_once('./eveitapi/class.charselect.php'); $api359 = new Api(); $api359->debug(false); // enable debugging $api359->cache(false); // do not use a cache-file, if one exists $api359->setCredentials(" . $GLOBALS['vbulletin']->userinfo['field6'] . "," . $GLOBALS['vbulletin']->userinfo['field7'] . "); $uchars359 = $api359->getCharacters(); $chars359 = CharSelect::getCharacters($uchars359); $eveitapi = $chars359[0][charname]; $charblahtest = \"Hello\"; echo \"Hello\"; |
What editor are you using? Looks like all linebreaks are removed.
|
Just to clarify you are placing this code in a PLUGIN correct? (AdminCP > Plugins and Products > Add New Plugin)
And not a TEMPLATE? (AdminCP > Style Manger....) You keep saying plugin template its confusing as to what you mean exactly as they are two different things. |
The plugin article said a plugin is a variable that display the contents of another template. I've been putting the code in this second template. Should the code be in the plugin itself? The plugin code is currently
Code:
$eveitapi = fetch_template('eveitapi'); |
I'm not sure what article you were reading but a Plugin is a peice of PHP Code that is excuted at a certain location (the hook location) by vBulletin. You PHP Code must go inside a Plugin.
You can use a Plugin to fetch a template, a template is front-end HTML that is displayed to the user. You can use variables in your template that get their values from the PHP code, but you cannot execute PHP code inside templates. Think of it like this (this is just a demonstration of how the system works you do not need to use this code at all!): PHP Code:
|
I tried putting the code in a plugin with hook global_start but variables weren't available to the template. When I put the code directly in the php file things work. Are there any security issues with putting the code directly in the php file?
|
What template was it? and make sure you checked that the variables actually had some data in them. Also make sure you eval()'d the template like this (if you are using a custom one)
PHP Code:
I doesn't make much difference if you place your code in Plugins or PHP files, but the plugin system is there so you don't have to mess with Files. |
The file is 'eveit.php'. The template is 'eveit'. It is working just fine with the API code in the PHP file. The template is called at the very bottom of the PHP file
PHP Code:
|
If the code you're wanting to put is in your own custom file, by all means, put that code in your file. Plugins are mainly for vBulletin so that when you update, your edits aren't lost.
|
All times are GMT. The time now is 02:59 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 | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|