Expand my Community achievements bar.

SOLVED

Creating new namespaces and mixins

Avatar

Level 2

Hi,

 

Wondered if anyone else has achieved this? In the past I created them through the java APIs (onprem) but I think that might be locked down with AEMaaCS.

 

Whats the best approach?

 

I've tried to create them via the repository initializer, i.e.

register namespace (example) http://www.example.com/jcr/example/1.0
register nodetypes
<<===
<< <example='http://www.example.com/jcr/example/1.0'>
<< [example:customitem]
<< mixin
<< - name (string) mandatory
===>>

 

This doesn't work, but interestingly with just the register namespace statement, that at least works, which leads me to believe the parser is having difficulties in processing the register nodetypes.

 

I've also tried through cnd files, but I've not see the install pick them up.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi,

thanks for the response. In the end had difficulty with these options too, but did find a way that works in the end. Will post it here incase someone else (or future me) comes looking for answers.

Simply create a node_name.cnd file, instead of using either the repository initializer (which doesn't seem to work), programmatically creating it (seems to be blocked regardless of permissions in AEMaaCS), then save it to a project content package (i.e. ui.content) under ./src/main/content/META-INF/vault/node_name.cnd

Documentation suggests META-INF/nodetypes, but vlt picks them up by default from the vault directory and installs them.

Cheers!

View solution in original post

2 Replies

Avatar

Community Advisor

Hi @raininglemons ,

Creating new namespaces and mixins in AEM can be achieved through various approaches. Here are some possible approaches:

1. Using the Java API: As you mentioned, this approach may not be available in AEM as a Cloud Service. However, if you are using an on-premise version of AEM, you can still use the Java API to create new namespaces and mixins.

2. Using the Repository Initializer: The Repository Initializer is a feature in AEM that allows you to define custom content structures and configurations. You can use this feature to register new namespaces and mixins. However, as you mentioned, the syntax for registering nodetypes may not be correct in your example. Here's an example of how you can register a new namespace and mixin using the Repository Initializer:

```
{
"jcr:root": {
"example": {
"@jcr:primaryType": "nt:unstructured",
"@xmlns:example": "http://www.example.com/jcr/example/1.0",
"customitem": { "@jcr:primaryType": "nt:unstructured",
"@jcr:mixinTypes": ["example:mixin"],
"name": {
"@jcr:primaryType": "nt:unstructured",
"@jcr:mandatory": true,
"@jcr:requiredType": "String"
}
}
}
}
}
```

In this example, we define a new namespace "example" with the URI "http://www.example.com/jcr/example/1.0". We also define a new mixin "example:mixin" and apply it to the "customitem" node type.

3. Using CND Files: CND (Compact Namespace and Node Type Definition) files are used to define custom node types and namespaces in AEM. You can create a new CND file with the definitions for your new namespace and mixin, and then install it in AEM using the CRXDE Lite or the Package Manager. Here's an example of a CND file that defines a new namespace and mixin:

```
<example='http://www.example.com/jcr/example/1.0'>
[example:customitem] > nt:base mixin
- name (string) mandatory
```

In this example, we define a new namespace "example" with the URI "http://www.example.com/jcr/example/1.0". We also define a new mixin "example:customitem" with a single property "name" of type "string".

Once you have created your CND file, you can install it in AEM using the CRXDE Lite or the Package Manager. After installation, you should be able to use your new namespace and mixin in your content structure.

Overall, the best approach for creating new namespaces and mixins in AEM depends on your specific requirements and constraints. The Repository Initializer and CND files are both viable options for creating custom content structures, while the Java API may be more suitable for complex customizations.

Avatar

Correct answer by
Level 2

Hi,

thanks for the response. In the end had difficulty with these options too, but did find a way that works in the end. Will post it here incase someone else (or future me) comes looking for answers.

Simply create a node_name.cnd file, instead of using either the repository initializer (which doesn't seem to work), programmatically creating it (seems to be blocked regardless of permissions in AEMaaCS), then save it to a project content package (i.e. ui.content) under ./src/main/content/META-INF/vault/node_name.cnd

Documentation suggests META-INF/nodetypes, but vlt picks them up by default from the vault directory and installs them.

Cheers!