Skip to main content

CQ SideKick Customization - Reload page on preview

Sometimes it is necessary to override default behaviour of CQ Sidekick. 

For example, you need to reload the page when author presses "Preview" button to apply some javascript logic or rename buttons in Sidekick, etc.

There are two ways to do it:
1). Straightforward (ugly). You need to copy script init.jsp from "/libs/wcm/core/components/init" directly under your application folder, customize it and include it from your page. (You can also copy this script under /apps but that would affect all other applications on this CQ instance).
Let's reload the page when author clicks on Preview button.

For that we need to change these lines:
    CQ.WCM.launchSidekick("<%= currentPage.getPath() %>", {
        propsDialog: "<%= dlgPath == null ? "" : dlgPath %>",
        locked: <%= currentPage.isLocked() %>,
        previewReload: "true"
    });
Notice previewReload property, it does the trick.

Next we need to include this script from our page component:
    <cq:include script="/apps/skywalker/init.jsp" />

2) Programmatic (preferrable approach).
Inside your page component please use the following code:

<script>
    function checkSidekickStatus() {
        if (CQ.WCM.isSidekickReady()) {
            CQ.WCM.getSidekick().previewReload = true;
            clearTimeout(timeout);
        }
    }
    var timeout = setInterval(checkSidekickStatus, 1000);
</script>

In other words, we wait until sidekick is loaded and then modify its properties. In this case we set previewReload to true. To check all available properties of sidekick please visit http://dev.day.com/docs/en/cq/current/widgets-api/index.html and search for "sidekick" there.


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 - Check if page is published or not

If you want to know if the page is published or not you can use the below utility method to know if the page is published or not. Steps - Take Resource Object. Adapt it to Page Adapt page to ReplicationStatus, you will get the status Here is the code - public static Boolean isPublished(Resource resource) { Boolean activated; ReplicationStatus status = null; activated = false; if (resource != null) { try { Page page = resource.adaptTo( Page.class ); status = page.adaptTo( ReplicationStatus.class ); } catch (Exception e) { LOG.debug(e.getMessage (), e); } if (status != null) { activated = status.isActivated(); } } return activated; }