Skip to content

Instantly share code, notes, and snippets.

@arumsey
Created May 22, 2024 18:26
Show Gist options
  • Save arumsey/d087294e29704b065ce08eaa86c1fe29 to your computer and use it in GitHub Desktop.
Save arumsey/d087294e29704b065ce08eaa86c1fe29 to your computer and use it in GitHub Desktop.
Using the Helix Importer createBlock function
/* global WebImporter */
/* Create a block of name/value pairs (eg. Metadata block) */
const metadata = {
...WebImporter.Blocks.getMetadata(document),
keywords: 'keywords',
"Publication Date": dateFromSourceDom,
};
const block = WebImporter.Blocks.createBlock(document, {
name: 'metadata',
cells: metadata
});
/* Create a block from an array of elements */
// Single row block with three columns
const items = [
[document.querySelector(''), 'a string value', [...document.querySelectorAll('div.someclass p')]]
];
const block = WebImporter.Blocks.createBlock(document, {
name: 'custom block name',
cells: items
});
// Single row block with variant
const items = [
[document.querySelector(''), 'a string value', [...document.querySelectorAll('div.someclass p')]]
];
const block = WebImporter.Blocks.createBlock(document, {
name: 'custom block name',
variants: ['stretch-start'],
cells: items
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment