Buy now for just €35.00
| Compatibility: | EE1, EE2 |
|---|---|
| Latest release: | 2.3.5 (released 2013-05-13) |
| Licensing: | Commercial License Agreement |
Creating your own Variable type
Creating your own Variable type is easy, especially if you've already created a FieldFrame fieldtype before. It uses a similar anatomy, with a slightly different naming convention.
Variable type name
It all starts with naming your type, like you would with a FieldFrame fieldtype. Once you have a name –
let's take My_new_type as an example – you need to create a folder in the
/system/modules/low_variables/types/ directory (EE1) or /system/expressionengine/third_party/low_variables/types/
directory (EE2), all lowercase: /my_variable_type/.
Inside that folder, create a file called vt.my_new_type.php, also all lowercase.
What you have now is /system/modules/low_variables/types/my_new_type/vt.my_new_type.php (EE1) or
/system/expressionengine/third_party/low_variables/types/my_new_type/vt.my_new_type.php (EE2) which
we'll need to edit.
If you're planning on using your own assets like css, javascript or images, you'll also need to create a new folder inside the
/themes/third_party/low_variables/types/ directory, with the same name, in which you can put your assets. For example:
/themes/third_party/low_variables/types/my_new_type/css/my_custom_styles.css or /themes/third_party/low_variables/types/my_new_type/js/jquery.plugin.js.
A basic variable type
A variable type should at least have an $info array and a function called display_input.
This is what a very tiny variable type looks like:
class My_new_type extends Low_variables_type {
var $info = array(
'name' => 'My new type',
'version' => '1.0.0'
);
function display_input($var_id, $var_data, $var_settings)
{
return '<input type="text" name="var['.$var_id.']" value="'.htmlspecialchars($var_data).'" />';
}
}
$info currently holds two keys: name, containing the display name of the variable type,
and version, containing the version of the variable type.
display_input returns the input field which is displayed on the home page of the Low Variables module.