Now, updated for Tiki 8!
Now accepting new user registrations! Become a contributor.
| More
Join Print Print multiple pages Convert to PDF

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.


Contributors to this page: Rick Sapir .
Page last modified on Thursday, October 21, 2010 10:23:38am EDT by Rick Sapir.
The content on this page is licensed under the terms of the Copyright Information.

Buy the Books

Tiki Essentials & Tiki for Smarties -- Buy the Books.
Available from Amazon, LuLu, and more as paperback or ebook...

What do you think?

What do you think of this project?



Anti-Bot verification code image Try another code



View Results
(Votes: 20)

"Definitely a must read for anyone undertaking a project using Tiki."

Is Essentials helpful?

Essential Readers



Advertising



Powered by Tiki Wiki CMS Groupware
Creative Commons Copyright. Some rights reserved.
Tiki Essentials (this site) is © 2011-2012 by Rick Sapir, published by KeyContent.org, and is licensed
under a Creative Commons Attribution-Share Alike 3.0 United States License. Some rights reserved. Privacy Policy.
Permissions beyond the scope of this license may be available at http://twessentials.keycontent.org/Copyright Information.
Questions, comments, or concerns about this site or the guide? Let me know.
New to Tiki? Try Tiki for Dummies Smarties: A beginner's guide to using Tiki Wiki CMS Groupware.


Feedback Form
Feedback Analytics