JavaScript code fix using AEM Page Property

Mayukh007

14-08-2020

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..!!

Accepted Solutions (1)

Accepted Solutions (1)

ChitraMadan

MVP

14-08-2020

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.

Answers (4)

Answers (4)

BrianKasingli

MVP

15-08-2020

@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. 

sunjot16

Employee

14-08-2020

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 !! 🙂

Varun_Shakya

MVP

14-08-2020

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