To start we must create the following files:
1. /usr/local/cwpsrv/var/services/user_files/modules/MY_MODULE.php
2. /usr/local/cwpsrv/var/services/users/cwp_lang/en/MY_MODULE.ini
3. /usr/local/cwpsrv/var/services/users/cwp_theme/original/mod_MY_MODULE.html
Where:
1. MY_MODULE.php: It is the file that will contain your new module, take into account that here you could be using the following variables:
-
- $ _SESSION [‘username’]: User name of the account.
- $ _SESSION [‘tokenuser’]: User session token.
- $ mod []: Fix with module information.
Example:
<?php
if(isset($_GET['acc'])){
if($_GET['acc']=='regards'){
echo 'Hello, This is a greeting from ajax to mymodule';
die;
}
}
$mod['dateday']=date('Y-m-d H:i:s');
$mod['msj']='Hi ';
?>
2. MY_MODULE.ini: It is the language file, it is mandatory for the English language.
Example:
LABEL1="Today's date is:"
LABEL2="Click here"
3. mod_MY_MODULE.html: It is the template of the theme, this file is required can receive parameters from the file MY_MODULE.php through the $ mod array using the template engine in Twig integrated to cwp.
Example:
<div class="row">
<div class="col-lg-12">
<strong>{{mod.msj}} </strong>{{langmod.LABEL1}} : {{mod.dateday}}
</div>
<div>
<button id="btn_hi" class="btn btn-xs btn-success">{{langmod.LABEL2}}</button>
</div>
</div>
In html templates you can make calls to the following variables of type array:
$mod = All the data that you send for it from the php
$langmod = All language tags
It is recommended to place all the javascript code in a library with extension .twig.
Example = /usr/local/cwpsrv/var/services/users/cwp_theme/MY_THEME/js/MY_JS.js.twig
Where the calls to ajax can be in this way:
$("#btn_hi
").click(function (){ $.ajax({ type: "POST", url: "./{{users}}/index.php?module=MY_MODULE&acc=regards", complete: function(datos){ alert(datos.responseText); return false; } }); return false; });
Note: It is recommended to clone the original theme and work on the copy since cwp updates always overwrite the original theme.