Token Classes

You can define PHP classes that will be loaded automatically on demand if a "mpf"-token calls for their functionality.

The basic structure of a token class has to be as follows:
<?PHP

class mpf_token_mytoken extends mpf_token{

/* available token parameters */ var $p=array( 'mytoken'=>'', 'parameter1'=>'', 'parameter2'=>'' ); function __construct($lib){ /* automatic registration of all parameters listed above */ $this->setParams($lib['params']); /* you may use $this->out to output data for use in templates */ $this->out="hello world " . $this->p['parameter1'] . $this->p['parameter2']; } }

 ?>


Example of usage in template (page or module):

{mpf:mytoken=[value]||parameter1=[value]||parameter2=[value]}

Global Class Instances

The following global class instances are available to be used in your token classes:

$mpf_store (value/variable store)
$mpf_parser (template parser)
$mpf_http (http related functions)
$mpf_string (string manipulation functions)
$mpf_fso (filesystem functions)

Example of usage in token class:
/* reference to global class instances */
global $mpf_parser;
global $mpf_store;

/* parse token string and store result in $myVar */
$myVar = $mpf_parser->parseBlock('{mpf:eval=1+2}');

/* save value of $myVar in global variable store */

$mpf_store->setVar('myResult',$myVar);

/* output value */
$this->out=$mpf_store->getVar('myResult');