How to add component attributes (before rendering)
Question
Hello,
I'm looking to auto create components inside a block element and it seems that I manage to do that but with a small missing... How I can pass component attributes for each one ??
The code is below and it's create multiple blocks. Each block has different type of component. By passing the blcoks Array inside the component object I manage to print trigger the grapesjs to print each component but unfortunately without the attributes (check img at the end)
Now since components are not render but they are generated as block I need to somehow store the attributes inside the model of each component and after a user use that particular block the component attributes to match
<a href="http://tinypic.com?ref=2e3qwyq" target="_blank"><img src="http://i68.tinypic.com/2e3qwyq.png" border="0" alt="Image and video hosting by TinyPic"></a>
for (let j = 0; j < arrBlocks.length; j++) {
if (arrBlocks[j].value.type === 'none') {
blockManager.add(arrBlocks[j].value.code, {
label: `<div class="gjs-block-label">${arrBlocks[j].value.code}</div>`,
attributes: {
class: 'gjs-fonts gjs-f-b1',
type: 'block',
},
type: 'component',
category: { id: 'block', label: 'Blocks', open: true },
content: {
classes: ['block-container'],
type: 'container-block',
components: arrBlocks[j].value.blocks,
copyable: false,
attributes: {
id: parseInt(arrBlocks[j].value.id, 10),
code: arrBlocks[j].value.code,
type: arrBlocks[j].value.type,
parameters: arrBlocks[j].value.parameters,
typeId: arrBlocks[j].value.typeId,
header: arrBlocks[j].value.header || " ",
content: arrBlocks[j].value.content,
classes: arrBlocks[j].value.classes,
actions: arrBlocks[j].value.actions,
filter: [arrBlocks[j].value.filter.locale, arrBlocks[j].value.filter.session],
},
}
});
}
}
Answers (2)
By what I see, from how you create blocks, it has nothing to do with the rendering of components, eg. parameters="null" is null because arrBlocks[j].value.parameters is null, that's all
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1325
How to disable drop for specific blocks/components
Hello, with the following code we are able to indicate if it's possible to drop other component(blocks) inside that particular component......
Issue #634
How can I pass content with script?
I made custom component like this way and used script as well then script is working fine but I am not able to select component. Is there a...
Issue #484
Can I restrict what blocks that can be dropped into a container
My intent is to create a block that should allow only image components (I'm using the default one from grapes-blocks-basic) to be dropped i...
Issue #1683
How to change id/class when new element drop on editor or render element with dynamic ip?
Hello @artf , Hope you are doing well. I have two questions regards dynamic blocks adding, 1) Is it possible to render the block with dynam...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.