AEM CQ 56 - Add new Switcher (Top Menu) Item

Goal


Add a link in welcome screen (http://localhost:4502/libs/cq/core/content/welcome.html) and new switcher (top menu) item in Classic UI console (/siteadmin, /damadmin etc.)

In the following steps we are going to add a sample CRXDE switcher item for navigating to CRXDE (http://localhost:4502/crx/de/index.jsp)

Package Install


Welcome screen




Classic UI




Solution


1) To overlay, create folder /apps/wcm of type nt:folder and /apps/wcm/core of type nt:folder

2) Create folder /apps/wcm/core/content of type sling:Folder

3) Create node /apps/wcm/core/content/crxde of type cq:Widget and following properties (another way is to copy /libs/wcm/core/content/siteadmin to /apps/wcm/core/content, rename accordingly, use vlt to sync node to your IDE and update the xml with necessary properties )

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:mixinTypes="[cq:Console]"
    jcr:primaryType="cq:Widget"
    sling:redirect="{Boolean}false"
    sling:resourceType="/apps/switcher-item-crxde/sample-crxde"
    sling:vanityOrder="{Long}143"
    sling:vanityPath="/sample-crxde"
    consoleDescription="Show CRXDE"
    consoleTitle="CRXDE"
    iconClass="crxde"
    jsLibs="[cq.wcm.admin]"
    title="CRXDE"/>


4) The property sling:resourceType above is basically the action associated with that switcher item; so on click, user is taken to resource /apps/switcher-item-crxde/sample-crxde. Lets create the necessary resource component

5) Create folder /apps/switcher-item-crxde of type nt:folder 

6) For adding necessary icon css ( iconClass property in step 3 ) create clientlib /apps/switcher-item-crxde/clientlib of type cq:ClientLibraryFolder with categories of type String[] and values cq.shared cq.widgets




7) Create file (nt:file) /apps/switcher-item-crxde/clientlib/css.txt, add
               
                                               ui.css

8) Create file (nt:file) /apps/switcher-item-crxde/clientlib/ui.css, add

#cq-switcher .cq-switcher-crxde {
    background: url(/crx/de/icons/16x16/unstructured.png) no-repeat;
}

#cq-switcher .cq-switcher-crxde-inactive {
    background: url(/crx/de/icons/16x16/unstructured.png) no-repeat;
}

#apps .crxde {
    background: url(/crx/de/icons/16x16/unstructured.png) no-repeat scroll 15px 20px transparent;
}


9) Create node /apps/switcher-item-crxde/sample-crxde of type sling:Folder 

10) Create file (nt:file) /apps/switcher-item-crxde/sample-crxde/sample-crxde.jsp, add the following code for redirecting user to CRXDE

<script>
    window.location.href = "/crx/de";
</script>



3 comments:

  1. Thanks for this tutorial. But how can I determine the order of console items?
    As I found out, the ConsoleUtil uses a query like "SELECT * FROM cq:Console ORDER BY sling:vanityOrder DESC" for fetching all items and orders them by vanityOrder DESC.
    If I test this with the CRX query tool I can see that setting a vanityOrder of 290 places my custom console item below the damadmin. But on the welcome page my custom item is always placed on top. So what am I doing wrong?

    ReplyDelete
  2. Hello Robert, I am experiencing the same problem. No matter which vanityOrder I set, the item is always on top on the welcome page. Did you find a solution for this?

    ReplyDelete
  3. Facing the same issue! If we put node in libs with other nodes, it displays at the bottom. But, if we overlay the functionality in apps, no matter what slingOrder, it displays at the top only.

    ReplyDelete