FooBank Documentation
The FooBank system allows you to define custom variables which can use to extend Vanilla's core configuration and behaviour. The easiest way to demonstrate this is by showing a few examples.
For FooBank to work in any of your pages or sidebars, the option to allow PHP code must be enabled for the page or sidebar where it is to be deployed (executed). FooBank values must not contain PHP tags.
Adding a New FooBank Object
- Expand the FooBank section from the main administration home page (make sure you're in advanced mode)
- Enter the name of the object in the 'Name' field - this must conform to PHP's naming conventions
- Enter the value of your object in the 'Value' field - this can be strings, scripts or functions
If you enter a FooBank object name that already exists within Vanilla's environment (e.g., $config_site_title), the FooBank variable will take precedence. This is not recommended and may cause unexpected behaviour.
Object Types
FooBank can handle a variety of different object types. Deploying each one within a page requires slightly different approaches. Check out the examples below for the most common types.
Variable
This type of FooBank object is the most simple - it's pretty much the same as using Smart Tags.
FooBank object
Name: foovar
Value: Hello World
Usage within page
<?php echo $foovar; ?>
HTML
This object type outputs ready-made HTML mark-up in your pages. Like PHP, double quotes must be escaped (using single quotes is easier).
FooBank object
Name: foohtml
Value: <p>Hello World</p>
Usage within page
<?php echo $foohtml; ?>
Script
This object type can perform a snippet of PHP code. Again, you must use single quotes or escape double quotes.
FooBank object
Name: foo_script
Value: echo 'Hello World';
Usage within page
<?php eval($foo_script); ?>
Function
Perhaps the most complex object type in terms of syntax, a FooBank function contains, you guessed it, a PHP function. Deploying the function in your page involves evaluating the object, giving it a runtime handle and then executing it. Like normal functions, you can pass it any number of variables you wish.
FooBank object
Name: fooFunc
Value: function fooFunc($var){ echo $var; }
Usage within page
<?php $fooFunc = eval($fooFunc); // this handler variable should be the same throughout fooFunc('Hello World'); // ditto when calling the function ?>
Screenshots of Various FooBank Types
Isn't using PHP's eval() function unsafe?
Like many features of PHP, it can be. However, the fact that Vanilla stores all of the code to be evaluated in a database reduces this risk to a negligible level. A possible risk might be how errors are reported by your server if your code fails - this could expose the true path of your server files. To be on the safe side, you could use the built-in options to keep your pages hidden or password-protected until you're sure the scripts within them work as they should.
