
Missing dialog functionality when creating a page in AEM? Learn how to include the `cq.authoring.dialog` category in CreatePageWizard using Granite UI.
When a new page is created, it is done with the Create Page Wizard. This is handy to know if your project has never had a need to customize it. Just like a component, it uses a .content.xml file to structure the the properties. This is how it is able to be customized - the same way as a regular component! You can overlay or extend page prop tabs as well!
Have you ever had something work perfectly fine in AEM's Page Properties dialog, only to have it stop working when creating a new page? Well, that's exactly the problem we're looking at here.
AEM's Create Page Wizard doesn't necessarily load all the same client libraries that are available when editing an existing page. And that's a little frustrating, considering that we're often using the same page properties and Granite UI components in both places.
One category I found particularly useful is cq.authoring.dialog. This category contains client libraries used for dialog functionality. But in the Create Page Wizard, that functionality wasn't being loaded in my implementation.
So instead of recreating functionality that already exists in AEM, why not just include the category ourselves? Turns out, Granite UI gives us a pretty simple way to do exactly that
The code below is a simple example of a Blog Tab for your page component. These are displayed when you create a new page (wizard), or edit the page properties (page edit).
Explanation of what “Blog Tab” contains:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/gui/components/authoring/dialog"
jcr:title="Blog Tab">
<content jcr:primaryType="nt:unstructured"
granite:class="site-authoring__dialog-fixed-columns"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
<items jcr:primaryType="nt:unstructured">
<tabBlogOptions
jcr:primaryType="nt:unstructured"
jcr:title="Blog Options"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<authors
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
fieldLabel="Authors">
<field
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/pathfield"
name="./authors"
rootPath="/content/your_site" />
</authors>
</items>
</tabBlogOptions>
</items>
</content>
</jcr:root>
Here is the small snippet of the code that needs to be included in the .content.xml file.
<customDialogClientlibs jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/includeclientlibs"
categories="[cq.authoring.dialog]">
</customDialogClientlibs>
Now for the actual fix!
Granite UI has a component called includeclientlibs that lets us explicitly load client library categories within our dialog. In this case, we're going to include cq.authoring.dialog.
This is an existing AEM authoring category, so we're not creating another clientlib or writing our own JavaScript. We're loading functionality that wasn't already available in our Create Page Wizard.
Add the following node under the items of the appropriate page-properties dialog container.
That's it! Well, almost. We still need to make sure our fields appear in the wizard and that the behavior we're expecting actually works.
Putting it together gives us:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/gui/components/authoring/dialog"
jcr:title="Blog Tab">
<content jcr:primaryType="nt:unstructured"
granite:class="site-authoring__dialog-fixed-columns"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
<items jcr:primaryType="nt:unstructured">
<customDialogClientlibs jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/includeclientlibs"
categories="[cq.authoring.dialog]">
</customDialogClientlibs>
<tabBlogOptions
jcr:primaryType="nt:unstructured"
jcr:title="Blog Options"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<authors
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
fieldLabel="Authors">
<field
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/pathfield"
name="./authors"
rootPath="/content/your_site" />
</authors>
</items>
</tabBlogOptions>
</items>
</content>
</jcr:root>
.. And now our multifields will properly work when creating a new page!
By explicitly including cq.authoring.dialog, we've made the category's dialog functionality available to our Create Page Wizard. In my case, this resolved the missing behavior I was seeing with the multifield during page creation.
One important thing to understand here is that standard Granite UI multifields don't generally require us to manually load this category just to function. This is about making additional dialog functionality available when the wizard doesn't already provide it.
The Create Page Wizard runs within the Sites console, not inside the Page Editor. Because of that, it doesn't necessarily load all the same clientlib categories used when editing an existing page's properties. That’s why things get a bit annoying when trying to manage your page’s tabs on Page Creation. Just because something works perfectly fine in Page Properties doesn't mean it'll work when creating a new page.
Of course, this doesn't mean every page needs it. If your page properties don't rely on additional dialog behavior during creation, there's no reason to include the category just for the sake of it. Additional dialog clientlibs should only be included in Create Page Wizard if your page type requires extra form functionality before page creation. Otherwise authors can fill those out later in Page Properties, where all your component-level clientlibs are already available.
There's also one more thing I'd be careful about.
cq.authoring.dialog is a shared category. Depending on your AEM version and the client libraries installed in your project, it can include more than just the functionality you're looking for.
That means you should test the Create Page Wizard after adding it, especially if your project includes additional custom dialog scripts.
AEM developer and frontend specialist with expertise in Adobe Experience Manager, React, and modern web development. Passionate about creating accessible, performant web experiences.
Comments
0 comments
Join the discussion
No comments yet. Have a question or something to add?