Skip to main content

Changing a CQ Component's Design Path


Changing a CQ Component's Design Path

Usually, the default location used by the CQ Designs configuration works, however there are cases where you may want to set the designs to exist at a different location. For example, you may want multiple components to share a configuration or have all of the instances of a component on a site share the same configuration.

CQ provides the EditConfig object which can be used to configure how the edit dialog is loaded in CQ.

To configure your design path in Adobe CQ, first set the edit context path in the Edit Config object when in design mode:

String myComponentDesignPath = currentDesign.getPath() + "/jcr:content/mycomponent";
if (WCMMode.fromRequest(request) == WCMMode.DESIGN) {
log.debug("Setting content path to {}", myComponentDesignPath);
editContext.setContentPath(myComponentDesignPath);
}

Next, you will need to retrieve the resource you at the path you configured as a ValueMap, to be able to retrieve the properties you set.

Resource myComponentDesignRsrc = resource.getResourceResolver().getResource(myComponentDesignPath);
if (myComponentDesignRsrc != null) {
pageContext.setAttribute("myComponentDesign", myComponentDesignRsrc.adaptTo(ValueMap.class));
}

Finally, once you have the design properties set as a page context attribute, you can retrieve the values in your component JSP.

${myComponentDesign.attribute}

The only unfortunate thing about this approach is that the currentStyles variable will no longer point to the correct design path.


Comments

Popular posts from this blog

CQ Page Properties from Javascript

To get CQ page properties inside javascript you can use core CQ JS API. It can be convenient if you need to get this information inside your custom JS widgets.              var pageData = CQ.HTTP.get(CQ.HTTP.externalize(CQ.utils.WCM.getPagePath() + "/jcr:content.json")); After that you can retrieve any property you need (assuming it's present in JCR):              var resourceType = pageData ? CQ.Util.formatData(CQ.HTTP.eval(pageData))['sling:resourceType'] : null; Please do not overuse it because it invokes additional ajax call to server. It's OK to use it in edit mode on author instance. Copied from -  http://adobecms.blogspot.com/2014/04/cq-page-properties-in-javascript.html

Forecasting EB-2/EB-3 Green Card Filing Dates - Machine Learning Model

In this blog post, we'll explore the process of forecasting Green Card filing dates using a simple linear regression model in Python. By analyzing historical data from the United States Citizenship and Immigration Services (USCIS), we can use basic machine learning techniques to predict future filing dates. I will walk you through the process step-by-step. Gathering Data:    To begin our journey, we need to gather relevant data. You can collect data from USCIS or other trustworthy sources. This dataset should include essential information such as the visa category, country of chargeability, and the final action date for each month. For this use case, I collected data manually from USCIS visa bulletin for India EB-2 and EB-3 categories. Data looks like this - Visa bulletin - Building the Linear Regression Model:    Using Python libraries like scikit-learn, we can construct our linear regression model. This simple yet powerful algorithm will help us forecast Green Card...

AEM 6.3 - How to extend Granite UI

Here in this article, I am going to explain how to extent Granite UI that is basically used to create AEM 6.x consoles. There can be various use cases where in you may need that. In our case, author wants to take all the page creation requests through AEM instead of email communication. Authors are basically looking for a form in AEM authoring console so that requestor can login and submit page creation/Asset upload request. Overall requirement is - Need a link in Navigation so that author can click on it and go to a Intake form. Author must be able to fill and save the intake requests. Author must be able to see the history of submitted intake requests Able to see the details of submitted intake requests. Solution - 1. Create a following structure - /apps/cq/core/content/nav/form and add the details given in below screenshot - You basically need to add - href, title and icon. Href is the path of page where user will land on clicking it.  Af...