Feb 06, 2013

Add default components in the Sidekick

Posted by Vianney Baron

Lately I've had a few developers come to me with the same question: how do you set the default components appearing in the Sidekick when first opening a page?

It's a legitimate question, switching to Edit mode for every page can be quite annoying, and we don't necessarily want to let the authors decide what components they are allowed to use in a particular Parsys.

However this is quite easy to fix, and here is how.

When building your web site with CQ, you will define a clientlib to store all your graphical assets (JS, CSS and images) as described in this post. But what developers often overlook is the fact that you can also use the clientlib to store meta information, like the list of default components appearing in Sidekick!

To see an example of this navigate to /etc/designs/geometrixx-outdoors/jcr:content/page/par in crxde and look at the properties of the node:


Here you see we are using the "components" property, and we're simply listing the components we want to see appearing in the sidekick when we open a page using the page component defined in our Geometrixx Outdoors application (this one: /apps/geometrixx-outdoors/components/page), this will also restrict the number of components your can drag and drop in this specific parsys, which can be really useful when you use different Parsys for different purposes on the same page. Simply put the path of each component in this String array and voila!

One more thing though: you might argue that having to list every single component in there is a bit annoying, but there's actually a way around that. You can directly use groups in there as well:


Then it becomes quite obvious that groups should be used as often as possible, especially because they are so easy to setup: simply add a "componentGroup" property to the root of you component and that's it (see here: /apps/geometrixx-outdoors/components/colctrl for example).