Appearance
Add specific blocks to site build
When you export the landing page to one of the target systems in eWizard, the eWizard.js builder adds all blocks from the blocks-library directory to the site build.
Use requireCurrentBlocks and the DynamicBlocksLoader component to ensure that the builder adds specific blocks to the build. This feature reduces the resulting build size and improves the site performance in the browser.
If you don't use the DynamicBlocksLoader component in the template, the eWizard.js builder adds all the blocks to the build.
The set of blocks in the resulting build is different for the development and production builds:
In the development build, eWizard.js checks blocks in the
blocks.jsonandblocks-themes.jsonfiles. As a result, it excludes all the blocks except the ones used in the specific theme or layout.In the production build, eWizard.js adds only the blocks from the
currenttheme of theblocks-themes.jsonfile. If the template doesn't have ablocks-themes.jsonfile, therequireCurrentBlocksis empty, and all blocks are included in the build.
To use requireCurrentBlocks:
Add the
DynamicBlocksLoadercomponent to theApp.vuefile of your site project or theindex.vuefile of your site page.html<!-- ./App.vue or ./pages/[SITE_PAGE_NAME]/index.vue --> <template> <wiz-root :class="[$editor.mode, ...$DT.rootClasses, { 'opened-in-editor': $editor.isOpenedInEditor }]"> <DynamicBlocksLoader :blocks-themes="blockThemes" :blocks-list="blocksList" ></DynamicBlocksLoader> </wiz-root> </template> <script> import { DynamicBlocksLoader } from 'ewizardjs'; import { themes } from './common/blocks-library/blocks-themes.json'; import { components } from './common/blocks-library/blocks.json'; export default { name: 'wiz-app', components: { DynamicBlocksLoader, }, data() { return { blockThemes: themes, blocksList: components, }; }, }; </script> <style lang="scss"> @import 'common/styles/imports.scss'; .previewer-app-container .root { width: 1920px !important; max-width: none !important; } </style>Import
requireCurrentBlocksto theglobalBlocks.jsfile.js// ./common/extensions/globalBlocks.js import { requireCurrentBlocks } from 'ewizardjs'; const blocks = requireCurrentBlocks(); export default function (Vue) { blocks.forEach((block) => { Vue.component(block.name, block); }); }
As a result, the production build includes only the blocks from the blocks-themes.json file.
Display specific blocks from a theme
You can use the name property of the DynamicBlocksLoader to display groups of default blocks from the blocks-themes.json file on a site layout or page. This is useful when configuring the content of your header, footer, and other site elements.
To display specific blocks from a theme:
Configure the displayed blocks in an array of the
defaultBlocksobject in theblocks-themes.jsonfile of the site. For example, thefooter-block-viseven-1block is included in thefooterarray:json// ./common/blocks-library/blocks-themes.json { "themes": { "viseven": { "blocks": [ { "id": "header-block-1", "name": "Header block 1", "icon": "/themes/viseven/media/images/blocks-icons/header-block-1.png" }, { "id": "footer-block-viseven-1", "name": "Footer block 1", "icon": "/themes/viseven/media/images/blocks-icons/footer-block-viseven-1.png" } ], "defaultBlocks": { "$default": [ "header-block-1", ], "footer": [ "footer-block-viseven-1" ], } } } }Add the name of your array to the
nameproperty of the<DynamicBlocksLoader>tag in theApp.vuefile of your site project or theindex.vuefile of your site page. For example,footer:html<!-- ./App.vue or ./pages/[SITE_PAGE_NAME]/index.vue --> <template> <wiz-page> <DynamicBlocksLoader :blocks-themes="blocksThemes" :blocks-list="blocksList" name="footer" ></DynamicBlocksLoader> </wiz-page> </template>
As a result, only the footer-block-viseven-1 block from the footer array is displayed on the layout or site page.