Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Add design path dynamically to Page

creative83
Level 3
Level 3

I have created a common page which will be used by two different site, so I can not attach one desig path to this page (etc\design) for dialog configurations. I wanted to dynamically assign the design path to page before it is loading through server side (in sightly class associated to page).

How can I achieve this? Is there any API or setter method I can use to do the same?

12 Replies
Hemant_arora
Level 8
Level 8

you can use the currentStyle com.day.cq.wcm.api.designer.Style implicit object to get the styles in sightly.

dylanr46798176
Level 3
Level 3

Is it a possibility to create 2 templates that have your custom page as a resourceSuperType and set the design paths on those 2 templates?

Hemant_arora
Level 8
Level 8

create one template and use 2 styles from dropdown field in page properties dialog

dylanr46798176
Level 3
Level 3

Perhaps a nice source to look at is this:

https://www.programcreek.com/java-api-examples/?code=wcm-io/wcm-io-cq5/wcm-io-cq5-master/sling/model...

This way you can imply your own custom logic to return a specific design at runtime.

creative83
Level 3
Level 3

My question was how to dynamically SET the design path. Reading is no thte problem.

All the above talks about GETing the design path, I want to SET the desing path using code at run time instead giving it as as page property.

dylanr46798176
Level 3
Level 3

Yes, the example in the link that I provided is a way of dynamically determining a design path, when a page is being requested.

creative83
Level 3
Level 3

It is not about determining at run time. I wanted to udpate the the design path at run time.

My page doesn't have desing path, so when page is loaded I wanted to assign it. There are certain conditions based on which at run time I need to setup design path out of multiple design path availble.

All above are talking about reading dynamically, my question is about setting update deisng path dynamically.

Hemant_arora
Level 8
Level 8

understood, thanks...looking for a probable solution. will keep you posted

dylanr46798176
Level 3
Level 3

I'm guessing you're not quite getting the point of what I'm trying to say here.

In the link I provided, you can write some custom code to create an injector that you can use to SET the design of the page to anything you wish, at runtime, without modifying the JCR.

You simply need to return a Design instance, based on the criteria your use case has (e.g.: return Design instance A when the requested path is /content/site1 and return Design instance B if the path is /content/site2)

creative83
Level 3
Level 3

THat sounds good, but how. Can you please share some code snippet and API function which can support the setter method of current page design path and at which instance I should inject it? Like when page is laoded there are default classed under WCMUse.

dylanr46798176
Level 3
Level 3

The link that I provided above is a code snippet on an injector that you need to create yourself. Basically, this injector will react on any kind of resource being requested and allows you to manipulate that resource, before being rendered. Please, first take a good look at that link.

To get a design/style by in Java, you'll have to use a Designer instance (Designer ("The Adobe AEM Quickstart and Web Application.") )

smacdonald2008
Level 10
Level 10

If you get this working - you should post the solution. It may help a lot of AEM ppl in the future.