currentStyle.<propertyName> is returning null in cq5 publisher, which is working perfectly fine in author. | Community
Skip to main content
Level 2
October 16, 2015
Solved

currentStyle.<propertyName> is returning null in cq5 publisher, which is working perfectly fine in author.

  • October 16, 2015
  • 9 replies
  • 2667 views

I checked that cq:designPath is same in author and publish but when I am using ${currentStyle.path} to get the design path in author and publish then there is a slight difference i.e.
author:
/etc/designs/default/jcr:content/default-page/par-main/column-control/par-col-1/breadcrumb
publish:
/etc/designs/default/jcr:content/default-page/column-control/par-col-1/breadcrumb
 I tried creating a new template with a new parsys say “par-main-1” but then “par-main-1” was missing in publisher.

I tried to resolve the issue by trying out the following.

  1. Activating the design node
  2. Deleting the page and creating a new page.
  3. Deleting components and dragging and dropping the component again on the page.
  4. I checked the JSON output of currentDesign and all the values am trying to access are available there.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by purnendraSingh

I am not sure if this is product bug or not but I solved this by removing one line of code from my template head.js .

I was inheriting my template from one of the "/libs" ( sightly)  page and there head.js was having below line of code so I just overlayed head.js in my template and commented out below line of code.  

    if(wcmmode.disabled) {

       request.setAttribute(Packages.com.day.cq.wcm.api.components.ComponentContext.BYPASS_COMPONENT_HANDLING_ON_INCLUDE_ATTRIBUTE, true); 

    }

I commented out this and every thing was back to normal. 

Check your template and check if you have this code some where .

9 replies

purnendraSingh
Adobe Employee
Adobe Employee
October 16, 2015

I am also facing same issue in currentStyle object in publish. My component is not using parsys and  it is a cq include in page

publish ,value of currentStyle is like  :/etc/designs/scholastic/campaign/email/jcr:content/reading-club-page

while on author it is  like /etc/designs/scholastic/campaign/email/jcr:content/reading-club-page/header-container/preheaderimage. 

I tried all steps given here but could not resolve this .

Is there a known solution for this ?

purnendraSingh
Adobe Employee
Adobe Employee
October 16, 2015

Note : Happens only if you are using this in sightly based templates. 

smacdonald2008
Level 10
October 16, 2015

Does this happen when you use JSP as opposed to Sightly? 

purnendraSingh
Adobe Employee
Adobe Employee
October 16, 2015

Yes.

Level 4
October 16, 2015

I haven't tried this with jsp but I'm doing something similar in Sightly/ javascript and encountering the same issue.   I've had to resort to something similar to the above comments : in preview/ publish mode fetch the design values via currentDesign.getJSON(), parse the value returned from that and then key into the values I want from the Json object.

Is this confirmed as a bug or an issue?  Or should I be coding something differently for publish mode...

// ...wcm use javascript snippet var n, p; if(wcmmode == 'EDIT' || wcmmode == 'DESIGN'){ n = currentStyle.get("foo"); p = currentStyle.get("bar"); }else{ // n = currentStyle.get("foo"); // p = currentStyle.get("bar"); ...these method calls return null - what to do here? }
purnendraSingh
Adobe Employee
purnendraSinghAdobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

I am not sure if this is product bug or not but I solved this by removing one line of code from my template head.js .

I was inheriting my template from one of the "/libs" ( sightly)  page and there head.js was having below line of code so I just overlayed head.js in my template and commented out below line of code.  

    if(wcmmode.disabled) {

       request.setAttribute(Packages.com.day.cq.wcm.api.components.ComponentContext.BYPASS_COMPONENT_HANDLING_ON_INCLUDE_ATTRIBUTE, true); 

    }

I commented out this and every thing was back to normal. 

Check your template and check if you have this code some where .

Level 4
October 16, 2015

Thanks Purnendra,

Actually my page is built with jsps (resource super type, foundation/components/page), perhaps the init scripts, global jsp etc do something similar to the code in head.js for page templates built in sightly?  I'll take a look.

Level 2
January 15, 2016

Hi,

 

Any updates on this issue. I am also facing the same issue in AEM 6.1 in sightly ?

Level 4
January 19, 2016

Sorry Promilag - no update from me.  I didn't follow the solution marked above as my page templates are built with jsp, so i left the sightly js using currentDesign.getJSON() to get the required values.