Skip to content

ashilkov/module-cms-import-export

Repository files navigation

CMS Import/Export module for Magento 2

This module provides fast, repeatable import and export for Magento CMS Pages, CMS Blocks, and Email Templates.

Key features:

  • Import via CLI (immediate and recurring) or Magento Admin Import (CSV only)
  • Export via CLI or directly from Admin grids
  • Multiple data formats: CSV (default), JSON, XML
  • Overwrite and merge options for flexible updates

Supported entities

  • CMS Pages
  • CMS Blocks
  • Email Templates

Import methods

  1. CLI — Immediate
  • Run a command with a path to a file. The import happens right away.
  • Supports CSV, JSON, XML.
  1. CLI — Recurring
  • Adds a new file named import.json into Magento's import directory (var/import/csv).
  • The file contains a list of filenames to be imported on the next bin/magento setup:upgrade.
  • Useful for committing import definitions into source control and applying them during deployments.
  1. Magento Admin — Native Import (CSV only)
  • Go to System > Data Transfer > Import.
  • Select the appropriate entity and upload a CSV file.
  • Recommended when you want a UI-driven import and only need CSV.

Export methods

  • CLI
  • Admin grids (Pages, Blocks, Email Templates) provide Export actions for CSV, JSON, XML, enabling quick one-off exports without CLI access.

Import/Export formats

Supported formats:

  • CSV (default)
  • JSON
  • XML

You can change the default format or add processors via Magento's Dependency Injection (see ContentProcessorPool in etc/di.xml).

CLI commands

Export

  • bin/magento cms:export:page <identifier> [-m|--merge] [--format=<format>]
  • bin/magento cms:export:block <identifier> [-m|--merge] [--format=<format>]
  • bin/magento cms:export:email <identifier> [-m|--merge] [--format=<format>]

Options:

  • -m|--merge — when exporting multiple entities sharing the same identifier across scopes, merges records into a single file (where applicable).
  • --format — one of csv, json, xml (default is csv).

Import

  • bin/magento cms:import:page [file_name] [-o|--overwrite] [-r|--recurring]
  • bin/magento cms:import:block [file_name] [-o|--overwrite] [-r|--recurring]
  • bin/magento cms:import:email [file_name] [-o|--overwrite] [-r|--recurring]

Options:

  • -o|--overwrite — overwrite existing entities when identifiers already exist
  • -r|--recurring — schedule import by appending entries to var/import/import.json and process on the next setup:upgrade

Note:

  • The file_name can be an absolute path, or a path relative to Magento’s import directory: var/import/cms/<entity_type>. For example, var/import/cms/page/homepage.csv. When a relative name is provided, the command looks for the file under that folder.

Examples

Export a CMS page to JSON:

bin/magento cms:export:page homepage --format=json

Export an email template (merge mode) to XML:

bin/magento cms:export:email newsletter_subscription --merge --format=xml

Immediate import of CMS blocks from CSV and overwrite existing:

bin/magento cms:import:block /var/www/magento/var/import/blocks.csv --overwrite

Schedule a recurring import for email templates:

bin/magento cms:import:email email_templates.json --recurring
bin/magento setup:upgrade

Installation

  1. Add a repository to composer.json:
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/ashilkov/module-cms-import-export.git"
    }
]
  1. Require the package:
composer require magecraft/module-cms-import-export
  1. Enable and upgrade:
bin/magento module:enable MageCraft_CmsImportExport
bin/magento setup:upgrade

Notes and tips

  • Import directory is Magento’s var/import. Ensure files are readable by the web/CLI user.
  • When using recurring import, maintain var/import/cms/import.json in VCS to make deployments reproducible.
  • CSV is the most portable format (supports Admin Import and grid exports). JSON/XML are recommended for richer structure and diffs in code review.
  • If you customize formats or processors, use DI configuration (etc/di.xml) to adjust ContentProcessorPool.

Support, feedback, and contributions

Author

About

Magento 2 module for CMS Pages, Blocks and Email Templates import and export

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages