Modules Overview

Last updated on July 24, 2024.

Modules allow for code reuse and sharing while, at the same time, protecting the intellectual property (IP) of creators and developers.

Directory structure

In your codebase, the directory needs to be at the same level as the directory.

You can split module code into two directories to protect IP (Intellectual Property). To create a module, split the module code into and folders, and place all that code into the directory.

and directories have the same structure as the standard folder. Still, if developers try to download or preview files after the module has been deployed to an Instance, they can only access the files from the folder.

In general, when referencing files that are part of a module, Insites uses a prefix that does not include any or folders (for example,  instead of ). This behaviour means that creators should not create files with the same name in both folders, as one will overwrite the other. This behaviour also gives creators flexibility: if they want to change the scope of the file, they can move it between the private and public folders without changing the code.

You can create an Instance and deploy the code as you would usually do, and you still can have the folder on the top level (this code will not be part of the module, but you can use it while developing).

This mechanism allows creators to share their module code and make it configurable (by code in the folder) while protecting the IP in the folder.

Example: Module directories

An example of module code split into two directories inside the directory:

Namespacing rules

Configuration files placed in a module are treated differently than regular files.
A namespacing strategy is used to avoid conflicts between the code of a module and regular code (or between modules).

The general rule of accessing files in modules is to prefix paths with . Remember that skipping resource type applies just like it does without modules. This behaviour means that when you access a , you type a path to it as if you were in the partial's directory.

When you use app:
Is accessed by path:

When you use module:
Is accessed by path:

The only difference is the prefix.

Examples

This section demonstrates the use of Modules for the following Insites elements:

  • Assets
  • Partials
  • Layouts
  • Records
  • Authorisation Policies
  • Translations

Assets

You can access assets placed in the  directory in a module using the asset_url filter.

Paths for those files are prefixed with

modules/admin/public/assets/app.css

modules/admin/public/assets/admin.js

Partials

Partials can be referenced with their shorter name - the same as the regular ones.
For example, to include partial saved as , you should use:

Layouts

Layout name has the same prefix when referenced within a page:

modules/admin/public/views/layouts/settings.liquid

Records

modules/admin/private/records/resume.yml

Authorisation Policies

modules/admin/public/authorization_policies/can_view_blog_posts

Within the page/form, it is referenced with a prefix:

GraphQL Query

The query looks like any other query:

But it is referenced with the prefix:

modules/admin/public/graphql/get_blog_instance.graphql

Translations

You should place the Translations YAML files for the module in: .

But when used in the module code, they should be prefixed, such as in the example below:

Related topic

Creating a Module

Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.