Issue #1547Opened October 29, 2018by ploutos270 reactions

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)

artfNovember 2, 20180 reactions

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

lock[bot]November 2, 20190 reactions

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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.