Important

Major updates are in progress. Some pages and languages may not be available.

Inputting Variables

In the first portion of our Pullquote plugin, you must define the variables that can be used in the plugin. In this example, there are three variables; two optional and one required:

  1. The text color — optional
  2. The overall width — optional
  3. The position (left or right) — required

Defining the Function

The first thing to do is to write the PHP code that defines the Pullquote function, as shown here:

The function
function wikiplugin_pullquote($data, $params) {
// Always include this line to read the data and parameters.

	$quote = '';

	}

The name of the function must be in the format wikiplugin_NAME OF YOUR PLUGIN. You can name your plugin anything you want — but do not include any spaces. The name that you use here, is the name of the plugin that users editing the wiki will use.

In this example, the plugin will be named pullquote. Therefore, the syntax to use it in a wiki page is: {PULLQUOTE()}...{PULLQUOTE}

The second line ($quote = '';) tells Tiki to set the quote (defined by the $quote variable) empty. This ensures that we start with an empty variable.

Reading the Variables and Setting Defaults

Now that the function has been defined, we can read in the three variables. In this example, we define the variables as:

  • $color — The text color
  • $width — The overall width of the pullquote
  • $float — Which side (left or right) of the page

In this example, we'll set the color of the text:

Setting the color
if (!isset($color))
	{
// Set default color
		$c = '#000000';
	} else {
		$c = '#'.$color;
	}


Notice that first we check to see if there is a color. Remember, the color is optional so it may not be included. If the user did not include a color code, the plugin defaults to #000000 (black text).

Notice too that we added a hash ( # ) to the beginning of the color code. This is important because HTML hex colors codes must start with a # sign.
We'll need to make sure that in the help we tell users not to include the # sign!

We can use similar code for the width:

Inputting width
if (!isset($width))
	{
// Set default width
		$w= '250px';
	} else {
		$w = $width . 'px';
	}

Here, we add px to the end of the width. Again, we'll need to make sure that in the help we tell users not to include the px with the width.

If the user did not include a width, the plugin defaults to 250px.

Error Handling

The third option, float (the position: left or right), is required. We can add logic to the plugin to confirm that the user has added a position.

Checking for the position
if (!isset($float))
	{
// No position, tell the user
		$msg = 'Please select a position: left or right.';
		return $msg;
		die;
	} else {
// Set the position
		$f = $float;
	}

Now, if the user forgets to enter a position, they'll be reminded.

Finally, we'll confirm that there is actual text to use as the pull quote.

Checking for text
if ($data eq '')
	{
// No text, tell user
		$msg = 'Please include text for the pull quote.';
		return $msg;
		die;
	}


Now, if a user tries to use the plugin without any text (such as {PULLQUOTE()}{PULLQUOTE} or {PULLQUOTE() /}) they'll get an error message.

Advertising