Skip to content

Latest commit

 

History

History
92 lines (72 loc) · 2.01 KB

File metadata and controls

92 lines (72 loc) · 2.01 KB
title Plugin Development
seotitle Develop Plugins in Markdown Master CMS
tags
Development
Plugins

Plugins should reside inside the extras/ directory and named with the key name of the plugin, along with an initialization script with the same name and a README.md file for user documentation.

example layout:

extras/
  | my-plugin/
    | my-plugin.js
    | README.md

Other files can be included as necessary, but only the primary will be loaded initially by the CMS.

Plugins are loaded by the CMS using the CMS.loadExtra() method, which generally is called from the theme index.html.

<script>
CMS.init();
// ...
CMS.loadExtra('my-plugin');
</script>

Plugin Configuration

Plugins support configuration options that can be passed by the site operator. This should be defined within either the theme settings.php or site-specific config.php files.

'extras' => [
    'my-plugin' => [
        'config1' => 'value1',
        'config2' => 'value2'
    ]
]

(Static-only installations can define them manually with the CMS.loadExtra() method.)

<script>
CMS.init();
// ...
CMS.loadExtra('my-plugin', {'config1': 'value1', 'config2': 'value2'});
</script>

These options can then be accessed via the CMS.config.extra method.

CMS.config.extra('my-plugin', 'config1', null); // returns 'value1' or NULL if not set

Logging

CMS.log.Debug('my-plugin', 'some debug message (only displayed when in debug mode)');
CMS.log.Warn('my-plugin', 'some warning message');
CMS.log.Error('my-plugin', 'some error message');

Require Other Plugins

{
	CMS.loadExtra('other-plugin');
}

Including Stylesheets

{
	if (CMS.config.extra('my-plugin', 'styles', true)) {
		// Allow the admin to set 'styles': false to skip loading auto styles
		let style = document.createElement('link');
		style.rel = 'stylesheet';
		style.href = CMS.config.webpath + 'extras/my-plugin/my-plugin.css';
		document.head.appendChild(style);
	}
}