Jump to content

Community

Developer Documentation

core/OutputPlugins

What it does

OutputPlugins allow you to add additional template plugins that can be called from templates in order to perform an action. Examples of built in template plugins include {url="..."} and {lang="..."}. OutputPlugins can support an unlimited number of parameters.

How to use

The extension will be generated with one property and one method.

    /**
     * @brief    Can be used when compiling CSS
     */
    public static $canBeUsedInCss = FALSE;

The $canBeUsedInCss property denotes whether or not the output plugin should be processed if used in CSS templates in the AdminCP. Some output plugins, such as hextorgb and url may be useful in CSS templates, while some may not be.

    /**
     * Run the plug-in
     *
     * @param    string         $data      The initial data from the tag
     * @param    array        $options    Array of options
     * @return    string        Code to eval )
     */
    public static function runPlugin( $data, $options )
    {
        // return valid PHP code as a string
    }
}

The runPlugin() method accepts two parameters, and should return an array or a string.

The first parameter is $data, which is the initial data for the tag (i.e. the value between the initial quotes). If your output plugin used was {myplugin="some value" option="other value"} then $data would be set to "some value".

The $options parameter is an array of options in key => value pairs. In the above example, there would be a key 'option' with its value set to "other value".

Your OutputPlugin extension should then return valid PHP code to insert into the compiled template. For example, the striptags plugin returns the following

    /**
     * Run the plug-in
     *
     * @param    string         $data      The initial data from the tag
     * @param    array        $options    Array of options
     * @return    string        Code to eval
     */
    public static function runPlugin( $data, $options )
    {
        return "strip_tags( $data )";
    }

Several output plugins exist out of the box. See our article on template plugins for more information on the existing plugins.


  Report Document


×
×
  • Create New...