In this article, you will learn how to import static blocks (or CMS) blocks to your Magento 2 store and how to export them. Along with the step-by-step instructions, you will find explanations on every static block attribute and sample files you can use as a reference.
Your Magento 2 store consists of CMS blocks and pages. When creating a new store or updating existing one you are probably composing new blocks, assign them to pages, and decide where you want these pages displayed.
This blog post about importing and exporting static blocks to Magento 2 is a part of educational blog posts about Magento 2 import and export processes. The rest of the posts can be found in:
So, static blocks or CMS blocks as they were called back in Magento 2 days. These are you ‘Lego-blocks’ when composing and building store content. Static blocks can be anything: widgets, banners, sliders, etc.
When it comes to optimizing workflows, if you are building several typical stores, or want to migrate from one to another, composing static blocks manually take much more time than intended. That’s why in this article we will describe how to import static blocks.
What you need to import/export statics blocks to Magento 2
For importing and exporting static blocks, we will be using Improved Import and Export extension for Magento 2. The extension is a full-featured import/export tool that can help you reduce the store management time by offering automated product catalog updates, order updates, and import and export of every Magento 2 entity you can think of.
The extension comes with the following features:
Import and export of all product types, product attributes, orders, categories, static blocks, CMS pages, cart price rules, MSI and other.
Import and export of B2B entities, such as: companies, requisition lists, shared catalogs, quotes and negotiable quotes.
Support of direct file upload, FTP, SFTP, direct URL, Dropbox and Google Sheets as import sources.
Support of CSV, XML, Json, XLSX, ODS file formats.
Mapping of CSV file separators and attribute mapping.
Filers and conditions including price, category, and other entity attributes.
Import speed of ~3000 per minute on a decent server configuration.
There are two ways to get sample tables with static blocks for Magento 2:
In the Master Import Table for Magento 2 – a Google Sheet table where we have gathered sample tables with every Magento 2 entity. Every attribute of every entity comes with a description, explaining how to use this attribute, and a sample value to give you better understanding of how the table works.
In the Firebear Studio GitHub. At the GitHub we have gathered sample tables of different formats including CSV, XML, Json, XLSX, ODS with every Magento 2 entity you can import and export. You can also find other sample files with XSLT templates and a readme file explaining how everything works.
Alternatively, if you have already installed Improved Import and Export extension you can try exporting the static blocks you already have at your Magento 2.
Exporting static (CMS) blocks from Magento 2
Once installed, Improved Import and Export extension introduces its sections to System > Improved Import/Export. There you can get access to the import and export jobs – a basic set of settings that let you perform manual or automatic import or export of required entity, in a required file format, on set conditions.
If you proceed to System > Improved Import/Export > Export jobs you will see an export job grid where you can create new jobs and manage existing jobs.
The export job grid comes with the set of filters and mass actions just as every other Magento 2 grid.
To create a new job click ‘Add New Job’ button.
In the General Settings of the export job you are suggested to specify the job name, set the job schedule if you want to execute it manually, and if the schedule is set – enable or disable the job to run automatically.
Below the General Settings, you will find Export settings. Here you decide which entity you want to export, in this article, we will be exporting CMS blocks; however, there are more entities available:
You can also set up a Consecutive Export – if it is enabled and the export job is set to run automatically, every consecutive execution of the job will only export NEW entities, that have been created in Magento 2 since the last execution of the job.
For example, if you are running the export jobs on a weekly basis, the consecutive jobs will let you export only the entities that you have created in your Magento 2 store the last week.
In the Export Behavior, you decide on the file format you want to export the data into and set the export file separator values.
In the Export Source configuration section you select the export source:
And specify the path to the file the data should be exported to. The files are created automatically and can be downloaded right from the export job screen after the export is complete.
Once you are done with the export job settings, click ‘Save & Run’ button and execute the job. The static blocks will be exported to the specified file format.
Composing and editing static blocks table
So, you have either exported or downloaded a table with static blocks. Now we can proceed to explain how one can edit such tables. Below, I will be explaining all attributes available for static blocks and how to edit them.
In the administrator panel, can be found in the link of the static block preferences page. For example:
Where ‘19‘ is the block ID.
Content of the static block
Can contain any symbols and references. Just as when you create and edit a static block.
<p>Content of the <strong>custom static block #1</strong>.</p>
The time the static block has been created
Only the following date format is allowed:
Static block ‘Identifier’. A unique name of the static block that is used as a reference for internal purposes.
Can be up to 64 latin characters in length, without spaces, can contain “-“, “_”.
‘Enable Block’ setting of the static block. Defines if the block is enabled or disabled.
1 – enabled
‘Block Title’ of the static block. Can contain any value. A name of the static block.
Can contain any value. A name of the static block.
Custom static block #1
The time the static block has been last updated
Only the following date format is allowed:
The code of the store view the static block belongs to.
Can contain multiple store view codes separated by comma without spaces.
Store View Code can be found under: Stores > All Stores > next, click required store view and check “Code” column.
Store View 1,Store View 2,German Store
That’s it, these are all the static block attributes that can be exported, edited and imported.
Importing static (CMS) blocks to Magento 2
The import process is similar to that of the export. To import static blocks using Improved Import and Export extension proceed to System > Improved Import/Export > Import jobs screen to find the import grid.
The import grid offers the same functionality as the export grid. You can filter already created jobs, edit the jobs directly from the grid, or create new jobs. Create a new job by clicking ‘Add New Job’ button.
In the General Settings of the job you are suggested specifying job name, schedule and other settings that can be found in the Improved Import and Export manual.
In the Import Settings you decide whether you want to use API connection, REST or SOAP, and specify the entity you are importing. In this blog post, we stick to the CMS blocks.
In the Import Behavior, you specify how the extension should treat the entities in the table you about to upload. A set of available behavior differs per imported entity. For static blocks the behavior includes:
Add – new entities will be added to the existing ones, if entities with same ID and identifier already exist, such entities will be updated
Delete – entities from the imported table will be removed from the store.
Replace – entities with the same ID and identifier will be replaced.
Along with the behavior you control allowed error count and can map imported file for separators.
In the Import Source section, you specify the format of the file you will be uploading: CSV, XML, Json, XLSX, ODS. Specify the import source:
If you are following this blog article instructions, you can import the sample static block table from the Google Sheet Master Import table we’ve talked about earlier.
When the table you are importing is uploaded you hit ‘Validate file’ button and let the extension check the file for proper data format. Then you can click ‘Save & Run’ button and execute the import job.
That’s it. You now know and understand how to import and export CMS static blocks to your Magento 2 store. If you require further assistance or have any questions – don’t hesitate to contact us via chat or support ticket.