whatscool
whatscool

Reputation: 317

Use an AEM component from another site

I have an AEM instance which serves multiple sites. One site has a component in use. I want to use this component on another site. I don't want to copy and paste the component files over to the second site and split the codebase like that. Does anyone know a way to use this component on another site?

Upvotes: 3

Views: 1013

Answers (2)

theopendle
theopendle

Reputation: 356

Say you have two webistes site1 and site2. Components for site1 would be in component group Group1 and components for site2 would be in component group Group2.

Using component groups (quickest and dirtiest)

All you would need to do is add the Group2 component group to the site1 component you want to use.

Using policies (less quick and dirty)

In your page templates for site2, define a policy that allows the authors to use components from component group Group2 but also any chose components from Group1

Using inheritence (sexy)

As Oliver mentioned, extract the shared components and put them in a third site (eg: sitecore, siteshare or something similar). This website is for organizing your components, not for adding and publishing content.

Then in site1 and site2, create components that simply reference those in sitecore using the sling:resourceSuperType property. Your site1 and site2 components will inherit all the the properties and edit dialogs of the referenced components.

If you want to override the cq:dialog or CSS of your inherited components you can do that too, to give each site a slightly different look-and-feel or behavior.

Upvotes: 4

Oliver Gebert
Oliver Gebert

Reputation: 1176

You can use each component on any site usually. There are several ways to organize your dependencies if you are also having several projects (or several folders in /apps).

Make sure to make use of inheritance (resourcecSuperType) and wrapper components if you are planning to do some project specific changes to some of the reused components. In order to have a clean dependency hierarchy it might also be useful to extract components that are used in more than one project to a "base" or "foundation" project.

Have a lookt at wcm core and we-retail. We-retail is reusing the wcm core components.

HTH.

Upvotes: 3

Related Questions