Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

JavaScript code fix using AEM Page Property

Avatar

Level 4

HI,

 

I have a situation where is there a CSS/JS which is causing multiple components in several pages visual disruption. We have a JS fix for that as interim solution which we can add in AEM Page property under "JS/CSS" section. That fixes the issue in the page.

We can not go for release now and that is why trying to fix using page prop as interim solution.

 

Question is: Is there anyway to propagate this JS fix from parent page's page prop to child pages..? Otherwise we have to manually add that piece of JS code in each of the pages which is almost like 300 pages..!!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Mayukh007,

 

You can run the groovy script to add the required page property in the 300 child pages.

 

Please find below the steps:

Screenshot 2020-08-14 at 22.07.38.png

  • Now go to http://localhost:4502/groovyconsole and write script something similar to this.
  • def path = "/content/whatever/parentpage";

    getPage(path).recurse { page ->

    def jcrContentNode = page.node;
    jcrContentNode.setProperty("newProperty" , "value");
    println("Property Added!!" + page.getPath())

    save();

  • There are 2 approaches for doing this, which you will have to decide:
  • You can either bring the content which needs to be updated in lower environment, run the script and then upload to production
  • Or You can directly run the groovy script on production author, make sure to take its back up for worst case scenario
This approach will take care of your existing pages and adding property in template will help for the newly created pages as suggested by other replies.

View solution in original post

9 Replies

Avatar

Community Advisor

Try adding the fix at template level. This might solve the issue for most of the pages.

Avatar

Employee

Make the necessary change(s) in the template(s) that are used to create those pages. That would fix the JS/CSS errors on all the pages that are created using that template.

 

I hope it helps !!

Avatar

Correct answer by
Community Advisor

Hi @Mayukh007,

 

You can run the groovy script to add the required page property in the 300 child pages.

 

Please find below the steps:

Screenshot 2020-08-14 at 22.07.38.png

  • Now go to http://localhost:4502/groovyconsole and write script something similar to this.
  • def path = "/content/whatever/parentpage";

    getPage(path).recurse { page ->

    def jcrContentNode = page.node;
    jcrContentNode.setProperty("newProperty" , "value");
    println("Property Added!!" + page.getPath())

    save();

  • There are 2 approaches for doing this, which you will have to decide:
  • You can either bring the content which needs to be updated in lower environment, run the script and then upload to production
  • Or You can directly run the groovy script on production author, make sure to take its back up for worst case scenario
This approach will take care of your existing pages and adding property in template will help for the newly created pages as suggested by other replies.

Avatar

Community Advisor

@Mayukh007,

You can have all your child pages inherit the page property from the parent page. From Sightly HTL, you can use the "inheritedPageProperties" helper.

 

<script data-sly-test="${inheritedPageProperties.jsConfigPath}" src="${inheritedPageProperties.jsConfigPath}"></script>

 

When you apply this script into the basepage.html, all children pages should be able to pick up the JavaScript config path as expected. 

Avatar

Community Advisor

You can use context aware configuration to achieve propagation of parent property to children pages

https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configurati...



Arun Patidar