Enonic application structure

Is it possible to set conditionals for content types/parts/layouts for sites in an application?
https://discuss-3.enonic.com/t/disable-enable-content-type-usage-per-site/2108

If I have to create a seperate application for each site in able to restrict content types/parts/layouts, can I use a global setting to get content types/parts/layouts in the application? or do I need to define this in each seperate application?

It’s a bit difficult for me to give good answers to all your questions without knowing a bit more about your situation and needs, but I’ll try:

Can you tell us a bit more what you mean by “conditionals”? Is there a specific action that you want to accomplish, or an action that you want to disallow? Your link is to a thread that has answered “no” regarding the ability to enable/disable content types for a specific site, so is there something different in your case that you need answered?

In the application code you can get a list of all content types by using getTypes() in lib-content. But you mention a global setting. Are you talking about something you want your application code to do, or are you talking about features in Content Studio? If you want your application code to get a list of all parts and layouts, there isn’t a JavaScript API for this, but this could perhaps be accomplished in Java in similar ways to how the Applications tool provides a list of parts and layouts.

In your “hidden fields” question, are you asking if it is possible to hide input fields that are shown when you fill out a new content? One possibility is to use Option Sets, even if all you need to select between is just a switch for enabled/disabled. Option Sets will then only show the input fields for the option that is selected. https://developer.enonic.com/docs/xp/stable/cms/schemas#optionset

Page Controllers are the most common way to show the visitor a result in the browser when they visit a URL on your site. In addition to providing the logic for rendering a page, they have regions where you can place other components (layouts, parts, text…) in the Content Studio page editor. The examples you give (“index” and “empty”) are specific implementations of Page Controllers in your application.
Technical info: https://developer.enonic.com/docs/xp/stable/cms/components

I’m not sure if the reason for your last question about Page Controllers is if you also wonder if you can allow/disallow certain Page Controllers for certain content, but in any case you can do this with Page Templates.
More info: https://developer.enonic.com/docs/content-studio/master/editor/page-editor

Ash Bhj mentioned, your usecase could help with the answer.

Enabling and disabling content types for each site can be difficult.
The way i solved it working for a customer is by having one app that contains the shared content types.
And each site having an application with its site specific content types. Then just install the application on the sites where they are needed.

3 question in one topic is at least 2 many. :slight_smile:

I removed the two other questions, I only need the answer for #1.
If I have to create a seperate application for each site in able to restrict content types/parts/layouts, can I use a global setting to get content types/parts/layouts in the application? or do I need to define this in each seperate application?

Example:
I create three seperate applications A,B and C (three seperate sites). I want to use some of the content types/parts/layouts in all three applications(sites). Is it possible to define this “globally” or do I need to specify this for each appliction? Would be a similare consept to using mixins

You can create a library (or other build trick) to add the content type to your apps at build-time.

Also, potentially content types can be created with Java, and register at app init. Buy I would not recommend this approach.

Hi Kristian,

Have a look at the Landing Page library. It’s one of the smallest libraries, but it shows with code how this works. The library is defined as a library in build.gradle, other than that it looks like a normal Enonic App. You build it and use gradlew install to install it in local maven (only on your own computer), or publish to some external repo. After this you can add it as a dependency to any of your apps trough build.gradle, and you will use that Content Type as if it was placed within that App directly. This makes it easy to share content types, components, and other things between multiple apps but maintain it in one place.

1 Like