Expand my Community achievements bar.

SOLVED

Access CQ5 component properties from CQ template jsp page

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 6

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

View solution in original post

2 Replies

Avatar

Correct answer by
Level 6

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

Avatar

Employee

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");