Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Add design path dynamically to Page

Avatar

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

Avatar

Level 8

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

Avatar

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?

Avatar

Level 8

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

Avatar

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.

Avatar

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.

Avatar

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.

Avatar

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.

Avatar

Level 8

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

Avatar

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)

Avatar

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.

Avatar

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

Avatar

Level 10

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