Hello world:


To learn how to create expansions with Webmatic you can create a simple "Hello world" expansion example.
To build the hello world expansion you need to create a new folder (called "hello") in "core/expansion/", in this new folder you must create the following files:

Filename (in folder core/expansion/hello/): Description:
config.php Is the expansion config file that contains all the configuration parameters for hello world exansion (see Expansions basis for details).
index.php This is the executable file. Is the php file that will contain the expansion code to be executed, you can create a different executable file for each expansion part but for this hello world example we use the same file ("index.php") for all the expansion part, that means all parts of the expansion (panels, pages, home, user area and administrator area) will execute the same code.
icon.png Is a 48x48 png file used as menu icon for administrator/user area.

You need also to create a folder for the language (called "lang") in "core/expansion/hello/", in this new folder you must create the languages files (only two language are used english and italian):

Filename (in folder core/expansion/hello/lang/): Description:
language_en.php English expansion language file, contains an array ($this->_WORD_EXPANSION[]) with all the terms used for English).
language_it.php Italian expansion language file, contains an array ($this->_WORD_EXPANSION[]) with all the terms used for Italian).

Hello world expansion files content:

Filename: "config.php" located in "core/expansion/hello/"
<?php

// Hello world and date expansion example (config file)

// An expansion config file must start with this line
defined('WM3_cEXEC') or die('Denied');

// General expansion configuration
$_EXPANSION['id'] = 1000; // Expansion unique ID (must be >= 1000 and different from any other expansion ID)
$_EXPANSION['version'] = '1.1'; // Expansion version
$_EXPANSION['wm_version'] = '3.0.5'; // Minimum Webmatic version needed to use the expansion
$_EXPANSION['language_path'] = 'lang/'; // Expansion language path to use different languages in an expansion

// Administrator stage config
$_EXPANSION['admin']['enabled'] = true; // You can use this expansion in administrator stage
$_EXPANSION['admin']['exec'] = 'index.php'; // File to execute when this expansion its used in administrator stage

// User stage config
$_EXPANSION['user']['enabled'] = true; // You can use this expansion in user stage
$_EXPANSION['user']['exec'] = 'index.php'; // File to execute when this expansion its used in user stage

// Page config
$_EXPANSION[0]['page']['enabled'] = true; // You can use this expansion inside a page
$_EXPANSION[0]['page']['exec'] = 'index.php'; // File to execute when this expansion its used inside a page

// Panel config
$_EXPANSION[0]['panel']['enabled'] = true; // You can use this expansion inside a panel
$_EXPANSION[0]['panel']['exec'] = 'index.php'; // File to execute when this expansion its used inside a panel

?>



Filename: "index.php" located in "core/expansion/hello/"
<?php

// Hello world and date expansion example (panel, page, administrator/user stage executable file)

// An expansion must start with this line
defined('WM3_cEXEC') or die('Denied');

// All the "echo" output will be rendered in the panel, page or administrator/user stage
echo $w3->getWordExpansion(3)." ".$this->getVersion(); // Render the word with index 3 from current expansion language file
echo "<br><br>Hello World!<br>";

// You can use all the api of webmatic.
// You can use also a global variable called "$w3", this variable is a global
// instance of "webmatic3" class. You can use $w3 to call all the public and
// non static methods of webmatic3 class
$date = wm3Util::renderDate($w3,time(),$w3->getHomeLanguage(),true,'',false);

echo "Today its $date";

?>


Hello world language files content:

Filename: "language_en.php" located in "core/expansion/hello/lang/"

<?php

// Expansion language file example

// An expansion language file must start with this line
defined('WM3_cEXEC') or die('Denied');

// Expansion words
$this->_WORD_EXPANSION[0] = "Hello world"; // Expansion title
$this->_WORD_EXPANSION[1] = "Hello world management"; // Expansion admin label
$this->_WORD_EXPANSION[2] = "Hello world management"; // Expansion user label
$this->_WORD_EXPANSION[3] = "This is the english version of hello world!";

?>


Filename: "language_it.php" located in "core/expansion/hello/lang/"

<?php

// Esempio di file per le lingue da usare in una espansione

// Un file per le lingue di un'espansione deve iniziare con la seguente righa
defined('WM3_cEXEC') or die('Denied');

// Termini usati nell'espansione
$this->_WORD_EXPANSION[0] = "Ciao mondo"; // Titolo espansione
$this->_WORD_EXPANSION[1] = "Gestione ciao mondo"; // Etichetta espensione (lato amministratore)
$this->_WORD_EXPANSION[2] = "Gestione ciao mondo"; // Etichetta espansione (lato utente)
$this->_WORD_EXPANSION[3] = "Questa è la versione italiana di ciao mondo!";

?>


You can download this expansion example (and other expansions) from www.valarsoft.com.