Create Block plugin
A plugin to create a block in a light module.
Package name |
|
Repository link |
|
Latest version |
|
Changelog link |
|
Prototypes available |
|
Installing
The plugin doesn’t come pre-installed with the Magnolia CLI.
You must add it to the mgnl.config.js
project file.
The plugin is installed automatically by the Jumpstart plugin if it is defined in a project template. |
Usage
Options
Form (short and long) | Description |
---|---|
|
Sets the light module for the block.
By default, uses the directory specified in the |
|
Use a path to the custom prototype templates directory as the prototype source for block creation. |
|
Selects a prototype for block creation. |
|
Displays the version. |
|
Displays help information. |
Examples
In the following examples, assume that the mgnl.config.js
file looks like this:
import CreateBlockPlugin from "@magnolia/cli-create-block-plugin";
export default {
plugins: [
new CreateBlockPlugin()
]
};
For more information, see Configuring plugins.
Create a new block
npm run mgnl -- create-block "my-block"
This command creates a new block called my-block
based on the _default
prototype.
The plugin will prompt you to:
-
Choose a directory containing all light modules.
-
Choose a light module directory where the new block will be created.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule
-
Create a new block in a specific light module
npm run mgnl -- create-block "my-block" --light-module "my-lm"
The command creates a new block called my-block
based on the _default
prototype in the my-lm
light module.
The plugin prompts you to choose a directory containing all light modules.
If the my-lm
light module doesn’t exist in the light modules directory, the plugin prompts you to select another one.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule
-
Create a new block based on a prototype from a custom prototypes directory
npm run mgnl -- create-block "my-block" --prototype-dir "/path/to/custom-prototypes-dir/block"
This command creates a new block called my-block
based on the _default
prototype from /path/to/custom-prototypes-dir/block
.
The plugin will prompt you to:
-
Choose a directory containing all light modules.
-
Choose a light module directory where the new block will be created.
If the _default
prototype is not present in the custom prototypes directory, it prompts you to choose another prototype.
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule
-
prototypeDir
-
prototype
-
The structure of the custom prototypes directory can be:
To use the custom
|
Create a new block based on a specific prototype
npm run mgnl -- create-block "my-block" --prototype "empty"
The command creates a new block called my-block
based on the empty
prototype.
The plugin will prompt you to:
-
Choose a directory containing all light modules.
-
Choose a light module directory where the new block will be created.
The Create Block plugin contains the |
The plugin writes the following properties to the mgnl.config.js
file:
-
Global
-
lightModulesPath
-
-
Plugin
-
lightModule
-
prototype
-
Configuration
You can set the following properties in mgnl.config.js
to predefine the plugin’s behavior.
Global properties
Property name | Description |
---|---|
|
The path to a directory containing all light modules. |
|
The name of a light module where the block will be created. Alternative forms: |
Plugin properties
Property name | Description |
---|---|
|
The name of a light module where the block will be created. Alternative forms: |
|
The path to a custom prototypes directory. Alternative forms: |
|
The name of a prototype. Alternative forms: |
For more information, see Configuring plugins.