Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

On saving the dialog by content author, need to modify multifield rich text html string

Avatar

Level 4

Hi, 

 

Need your thought on this:

 

I have multifield dialog with rich text and I need to add some dynamic html attributes in anchor link:

 

My thoughts: 

 

1. I can add a component specific client lib with category "cq.authoring.dialog" and then on keyup event I can get the html string and add html attribute in this string, then save it back.

If this is correct approach then I need your suggestions how I can get dialog properties in client lib file? Also, I need to do this on author instance only. 

 

2. My second thought is, I can add a sling modal and handle this on java side and return a formatted JSON

 

3. First I can set it through sly.set and added into a div container, then get div element by JS and add the html attributes, then set it back [this not preferable]

 

Ex: 

<sly data-sly-test = "${item.name == 'myMessages'}">
                <sly data-sly-list.item= "${item.listChildren}">
                <sly data-sly-set.myMessages = '${myMessages}${myMessages?",":""}"${item.messageName}" : "${item.myMessages @ context="html"}"'>
</sly>
       <div id = "domManipulation">${myMessages}</div>
                </sly>
            </sly>
 

Abhishekty_0-1703116227686.png

 

 Also, after this formatting I need to send this JSON to a SPA, So I don't want to this on SPA's script.

 

Kindly suggest good approach. I appreciate any feedback you share.

 

Thanks

Abhishek

 

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Abhishekty,

If you want to store data in repository with your dynamically added attributes, than option 2 and 3 will not be the good one, because they only decorates values stored in crx, and if you will request for it via OOTB REST api, those values will not be included.

Option 1 looks interesting, but again, if in the future you will decide to use REST api to modify content the change will not be applied.

Keeping in mind above, I would recommend to use SlingPostProcessor - this is OOTB mechanism that is executed automatically whenever you send POST that is handled via SlingPostServlet. SlingPostServlet is used by default every time you are saving your dialog, but also when you are manipulating data using curl.

This will guarantee consistency of your data in repository.

Here you can find a very simple example of modification data via SlingPostProcessor:

View solution in original post

2 Replies

Avatar

Community Advisor

For point 1 you can follow this link to read and update the values of dialog from client libs https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/set-current-page-title-to-...

point 2 is straightforward and let me know if you need any assistance on that as well

Avatar

Correct answer by
Community Advisor

Hi @Abhishekty,

If you want to store data in repository with your dynamically added attributes, than option 2 and 3 will not be the good one, because they only decorates values stored in crx, and if you will request for it via OOTB REST api, those values will not be included.

Option 1 looks interesting, but again, if in the future you will decide to use REST api to modify content the change will not be applied.

Keeping in mind above, I would recommend to use SlingPostProcessor - this is OOTB mechanism that is executed automatically whenever you send POST that is handled via SlingPostServlet. SlingPostServlet is used by default every time you are saving your dialog, but also when you are manipulating data using curl.

This will guarantee consistency of your data in repository.

Here you can find a very simple example of modification data via SlingPostProcessor: