Solved! Go to Solution.
Views
Replies
Total Likes
It depends how did you configure the component-model. If you don't use component grouping then you need to read the content from each row. If you use content grouping then you need to read just children nodes
https://www.aem.live/developer/component-model-definitions#element-grouping
Hi @pradeepdubey82 , EDS is new way of development and its a bit challenging for mind shift but once you master this we can build blocks and pages with ease.
Coming to your question of access fields in JS. We dont actually access fields in js, EDS renders content as html in output and we can play with HTML using JS for functionality or styling.
So using above documentation when you create a block, pls provide ID for the block along with your block definition, model, filter etc.
Once you choose to author this block in your page, universal editor shows these fields in content panel, once you author content, EDS generates HTML for you.
Now using Block CSS and JS you can customizations to it like below by targeting specific block with ID and its underneath elements.
Hope this helps.
I understood decorate function in js file is generating the html as per the need. But my question is 'block' attribute passed in decorate function, from the block reference how could I fetch the 'attributes' for that block?
I want to format the values/text and do some manipulation before rendering on page.
Is it possible in EDS?
Views
Replies
Total Likes
One way through JS could be
import { attach } from "@adobe/uix-guest";
let guestConnection;
useEffect(() => {
(async () => {
guestConnection = await attach({ id: extensionId });
})();
}, []);
const editorState = await guestConnection.host.editorState.get();
const { editables } = editorState;
const blockId = "your-block-id"; // Note : Replace with your block's ID
const block = editables.find(
(editable) => editable.id === blockId && editable.type === "reference"
);
if (block) {
const { resource, value } = block;
console.log("Block Resource:", resource);
console.log("Block Value:", value);
}
const formattedValue = formatRichText(value);
PS: You'll need to make sure the script is executed before the page is rendered. Headers(Immediate Load)
Footer(Lazy Load) - Need to hold rendering till the script is executed.
Thanks,
Kind regards,
Kiran Buthpur
here is the example of card block
https://github.com/arunpatidar02/aem-xwalk-1/blob/main/blocks/cards/cards.js
Hi Arun,
I have title and description field in in block. Card blcok has rows, so the logic is totally different here. Not sure how to fetch the individual fields from block object.
Views
Replies
Total Likes
It depends how did you configure the component-model. If you don't use component grouping then you need to read the content from each row. If you use content grouping then you need to read just children nodes
https://www.aem.live/developer/component-model-definitions#element-grouping
Views
Likes
Replies
Views
Likes
Replies