How to create a generator

This tutorial is for Joomla websites.

1
Create a folder with the name example and open it. To make the coding easier, use this name for everywhere, where it has to change.
2
Create a file called example.php, example.xml, index.html, choose a little image, which will be showed in the generator list, and make folders, depending on how many subcategories do you want, on first try make two, to understand it. Name these folders images and phones.
3

Open your example.php and put this code in:

<?php defined("_JEXEC") or die("Restricted access");
class plgNextendSliderGeneratorExample extends NextendPluginBase {
    var $_group = "example";
    function onNextendSliderGeneratorList(&$group, &$list) {
        $group[$this->_group] = "Example category";
        if (!isset($list[$this->_group])) $list[$this->_group] = array();
    $list[$this->_group][$this->_group . "_images"] = array("Images of phones", $this->getPath() . "images" . DIRECTORY_SEPARATOR, true, false, true, "");
        $list[$this->_group][$this->_group . "_phones"] = array("Phones and names", $this->getPath() . "phones" . DIRECTORY_SEPARATOR, true, false, true, "");
    }
    function getPath() {
        return dirname(__FILE__) . DIRECTORY_SEPARATOR;
    }
}
NextendPlugin::addPlugin("nextendslidergenerator", "plgNextendSliderGeneratorExample");
	

Parts of the code:

The name of your plugin:

plgNextendSliderGeneratorExample
	

The name of your main category:

$group[$this->_group] = 'Example category';
	

The names and folders of the subcategories:

$list[$this->_group][$this->_group . '_images'] = array('Images of phones', $this->getPath() . 'images' . DIRECTORY_SEPARATOR, true, false, true, '');
$list[$this->_group][$this->_group . '_phones'] = array('Phones and names', $this->getPath() . 'phones' . DIRECTORY_SEPARATOR, true, false, true, '');
	

If you want more, then you can add the same way, if you want less, then add only one.

4

The index.html remains empty.

Open example.xml, and put this in:

<?xml version="1.0" encoding="utf-8"?>
<extension version="1.5" type="plugin" group="nextendslidergenerator" method="upgrade">
    <name>Nextend Smart Slider generator: Example</name>
    <author>Roland Soos</author>
    <creationDate>2013</creationDate>
    <copyright>Copyright (C) 2013 nextendweb.com. All rights reserved.</copyright>
    <license>GNU General Public License</license>
    <authorEmail>roland@nextendweb.com</authorEmail>
    <authorUrl>http://www.nextendweb.com</authorUrl>
    <version>1.0.0</version>
    <description></description>
    <files>
        <filename plugin="example">example.php</filename>
        <folder>images</folder>
        <folder>phones</folder>
        <filename>index.html</filename>
        <filename>dynamic.png</filename>
    </files>
    <params>
    </params>
</extension>
	

Parts of the code:

The name of the extension:

<name>Nextend Smart Slider generator: Example</name>
	

The name of the file, which you just used:

<filename plugin="example">example.php</filename>
	

Folders you want to use:

<folder>images</folder>
<folder>phones</folder>
	
5

Now go to the images folder, make an empty index.html, a config.xml with this code in:

<root>
</root>
	

And a generator.php, which will be the soul of your generator, this will define the datas, which will be in the variables:

<?php
nextendimportsmartslider2("nextend.smartslider.generator_abstract");
class NextendGeneratorExample_images extends NextendGeneratorAbstract {
    function NextendGeneratorExample_images($data) {
    parent::__construct($data);
    $this->_variables = array(
        "image_url" => "Url to the image",
    );
    }
    function getData($number) {
    $data = array();
    $data[0]["image_url"] = "http://i-cdn.phonearena.com/images/phones/35145-specs/LG-Optimus-4X-HD.jpg";
    $data[1]["image_url"] = "http://earthandroid.files.wordpress.com/2012/08/lg.jpg";
    $data[2]["image_url"] = "http://i-cdn.phonearena.com/images/phones/40579-xlarge/LG-Lucid-2.jpg";
    $data[3]["image_url"] = "http://i-cdn.phonearena.com/images/phones/37737-specs/LG-Optimus-G.jpg";
    $data[4]["image_url"] = "http://www.lg.com/us/images/cell-phones/LG272/lg-mobile-LG272-large06.jpg";
    $data[5]["image_url"] = "https://www.homeneedsonline.com/products/bimages/lg-E615-mobile-phone-973717.jpg";
    $data[6]["image_url"] = "http://www.lg.com/uk/images/lg-mobile-phones/e610/gallery/medium03.jpg";
    $data[7]["image_url"] = "http://gsmotthon.hu/files/device/10000/9864/lg-optimus-l7-ii-p710-silver-01.jpg";
    $data[8]["image_url"] = "http://bacbs.com/images/latest-lg-mobile-phones.jpg";
    $data[9]["image_url"] = "http://www.lg.com/us/images/cell-phones/LG272/lg-mobile-LG272-large05.jpg";
    if (count($data) > $number) {
        $data = array_slice($data, 0, $number);
    }
    return $data;
    }
}
	

Parts of the code:

Name of the generator, and the folder:

NextendGeneratorExample_images
	

This will define, how many variables do you want to use in your slider, and their names:

$this->_variables = array(
    'image_url' => 'Url to the image',
);
	

This is the variable, that you will pass with the informations in it:

$data = array();
	

This will make sure, that there won’t be more slides, then the slide number in the backend is:

if (count($data) > $number) {
    $data = array_slice($data, 0, $number);
}
	

And the most important thing is the variables, this will be your first variable:

$data[0]['image_url'] = 'http://i-cdn.phonearena.com/images/phones/35145-specs/LG-Optimus-4X-HD.jpg';
	

It has the 0 as his place in the array, the image_url, as the name of the variable, which you specified (‘image_url’ => ‘Url to the image’).

6

Now let’s take a look at the other folder you have created(phones) and use three variables.

In this folder do the same, create an empty index.html, a config.xml with this code in:

<root>
</root>
	

Make a generator.php file, and put this code in it:

<?php
nextendimportsmartslider2("nextend.smartslider.generator_abstract");
class NextendGeneratorExample_phones extends NextendGeneratorAbstract {
    function NextendGeneratorExample_phones($data) {
    parent::__construct($data);
    $this->_variables = array(
        "phone_name" => "Name of the phone",
        "phone_type" => "Type of the phone",
        "phone_img" => "Image of the phone"
    );
    }
    function getData($number) {
    $data = array(
        array("phone_name" => "Samsung",
        "phone_type" => "Galaxy",
        "phone_img" => "http://www.wikitech.hu/uploads/2012/04/Galaxy-S-WiFi-4.0_2.jpg"),
        array("phone_name" => "LG",
        "phone_type" => "Optimus",
        "phone_img" => "http://i-cdn.phonearena.com/images/phones/35145-specs/LG-Optimus-4X-HD.jpg")
    );
    if (count($data) > $number) {
        $data = array_slice($data, 0, $number);
    }
    return $data;
    }
}
	

Here you can see, that there are 3 variables:

'phone_name' => 'Name of the phone',
'phone_type' => 'Type of the phone',
'phone_img' => 'Image of the phone'
	

And an other way then what we used in the previous example to put the datas into an array:

$data = array(
    array('phone_name' => 'Samsung',
    'phone_type' => 'Galaxy',
    'phone_img' => 'http://www.wikitech.hu/uploads/2012/04/Galaxy-S-WiFi-4.0_2.jpg'),
    array('phone_name' => 'LG',
    'phone_type' => 'Optimus',
    'phone_img' => 'http://i-cdn.phonearena.com/images/phones/35145-specs/LG-Optimus-4X-HD.jpg')
);
	

It’s the same as if you would do

$data[0]['phone_name'] = 'Samsung',;
$data[0]['phone_type'] = 'Galaxy';
$data[0]['phone_img'] = 'http://www.wikitech.hu/uploads/2012/04/Galaxy-S-WiFi-4.0_2.jpg';
$data[1]['phone_name'] = 'LG';
$data[1]['phone_type'] = 'Optimus';
$data[1]['phone_img'] = 'http://i-cdn.phonearena.com/images/phones/35145-specs/LG-Optimus-4X-HD.jpg';
	

Basically what you really need is the getData function, where you can use your variables, give them to an array, or just create your own list.

7
Put your example folder into a zip, and upload it to your website:
generator_create_2 Go to your Plugin Manager, search for your example plugin and enable it:
generator_create_3 Now you should see it in your backend, and you can use your custom variables:
example_generator Note: You won’t be able to choose a predefined layout for this generator, so you will have to do the layout manually with the Edit Layout option.