Access CQ5 component properties from CQ template jsp page | Community
Skip to main content
Level 2
October 16, 2015
Solved

Access CQ5 component properties from CQ template jsp page

  • October 16, 2015
  • 2 replies
  • 1341 views

Hi Experts:-

I have a scenario wherein i want to include certain Javascripts and Styles on template based on the checkbox selected in component which is included in the template.

Issue that I am facing is that I am able to access checkbox value only from component jsp while this value is not accessible from template jsp.

Is there a way to achieve this.

 

Also can i build a edit mode for the entire template itself.

 

Thanks

Sudeep

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 Ove_Lindström

Think injection.

It is not the template that should have the knowledge that the component might or might not need to load some scripts or styles. It should be that the template offers a way to any component to initialize loading of scripts and styles dynamically.

But, in my experience, having a content component alternating the look and feel of a template component is often harder and more unintuitive than actually having a template that can handle that sort of logic.

/Ove

2 replies

Ove_LindströmAccepted solution
Level 6
October 16, 2015

Think injection.

It is not the template that should have the knowledge that the component might or might not need to load some scripts or styles. It should be that the template offers a way to any component to initialize loading of scripts and styles dynamically.

But, in my experience, having a content component alternating the look and feel of a template component is often harder and more unintuitive than actually having a template that can handle that sort of logic.

/Ove

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

In the end component-properties are saved on a Node, when you know the path to the resource, you can access those properties.

Whether it is the right thing it another question, here some sudo-code:

Resource resource = getResourceResolver().resolve("yourpath/to/the/resource");

ValueMap vm = resource.adaptTo(ValueMap.class);

String myPropertyValue = vm.get("property","defaultValue");