Mecha CMS

Mecha CMS blog and documentation.

Dynamic Fields

Updated: Sunday, 07 August 2016

Creating dynamic custom fields from a file.

You can add more fields dynamically by creating a file named as fields.php, stored in a folder named as workers. This applies to shields and plugins:

Example for shield:

your-shield-name/
 ├── workers/
 │   └── fields.php
 ├── …
 ├── …
 └── …

Example for plugin:

your-plugin-name/
 ├── workers/
 │   └── fields.php
 ├── about.txt
 └── launch.php

The fields.php file only contains array of fields data:

<?php

return array(
    'custom_field_1' => array(
        'title' => 'Custom Field 1',
        'type' => 'boolean',
        'value' => 'true',
        'scope' => 'article'
    ),
    'custom_field_2' => array(
        'title' => 'Custom Field 2',
        'type' => 'text',
        'value' => 'Hello!',
        'scope' => 'page'
    ),
    …
);

The custom fields data above will be added to the post editor automatically so that you don’t have to tell the users to add such required fields for your awesome custom shields and plugins manually from the Fields manager:

Custom Fields Added Dynamically

Donation and Email Subscription