Table of Contents
easyvar Plugin
Compatible with DokuWiki
No compatibility info given!
This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.
Similar to fields, kixovar, macros, replace, textinsert
Based on KixoVar plugin by Kixo SARL infos [at] kixo [dot] fr. Adds two improvements. First, variables can be any length (KixoVar is limited to 2 to 5 characters). Second, you can use wiki syntax and HTML inside the variables.
I personally use this to include PayPal Add to Cart or Buy Now buttons to tables in my own Wiki so that I don't have to throw a bunch of HTML on each page.
Download and Installation
Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.
Adding Variables
You need to modify the default.php file in the plugins conf directory in order to add your variables.
Use
Once you have variables placed in the default.php file, you can simply insert those variables with @ (at) signs around them. So, @hello@ is replaced by “Hello World” using the included example file.
Source
Below is the source code for the plugin. You should, however, use the installation instructions above.
syntax.php
<?php /** * EasyVar Plugin: allows to insert your own variables * * Syntax : @variable@ will be replaced with valeurVariable * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Joel Dare <joel@joeldare.com> * * Based on KixoVar by Kixo SARL <infos@kixo.fr>. Adds two improvements. First, * variables can be any length (KixoVar is limited to 2 to 5 characters). * Second, you can use wiki syntax and HTML inside the variables. */ if(!defined('DOKU_INC')) die('Error'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); class syntax_plugin_easyVar extends DokuWiki_Syntax_Plugin { function getInfo(){ return array( 'author' => 'Joel Dare', 'email' => 'joel@joeldare.com', 'date' => '2009-12-28', 'name' => 'easyVar', 'desc' => 'Insert your own variables', 'url' => 'http://www.joeldare.com' ); } function getType(){ return 'formatting'; } function getSort(){ return 999; } function connectTo($mode) { $this->Lexer->addSpecialPattern('@\w*@', $mode, 'plugin_easyVar'); } function handle($match, $state, $pos, &$handler){ $match = substr($match, 1, -1); // strip markup return array($match); } function render($mode, &$renderer, $data) { $var=$this->getConf('var'); $meta = $data[0]; $nocache = false; $xhtml = $meta; if($mode=='xhtml' and sizeof($var)>0){ foreach($var as $key=>$value){ if($key==$meta){ $xhtml=$value; } } //$renderer->doc .= hsc($xhtml); $renderer->doc .= $xhtml; return true; } return false; } }
conf/default.php
<?php $conf['var'] = array('hello' => 'Hello World'); ?>