Creating Maintainable Interfaces with Snippets

Skip navigation

Creating Maintainable Interfaces with Snippets

Creating Maintainable Interfaces with Snippets by Arjan van IJzendoorn

In earlier posts I wrote about the changes to navigation in Mendix 5 and about the new layouts feature. Today, it is time to talk about another big new feature: snippets.

Snippets are reusable interface parts that allow you to create a more maintainable interface. If you use a snippet in multiple pages, you only have to make a change once and the result will show up everywhere. For example, you can create a snippet with some navigation links that you then show on several pages. If you make a change in the snippet, all pages will benefit.

My First Module Snippet Screenshot
A simple snippet with some navigation options

Snippets can also be connected to an entity. This means that you can then use the attributes of that entity while modeling the contents of that snippet, just like when you are modeling the inside of a data view. Such a snippet with an entity can be used inside a data view, template grid or list view.

Attributes Screenshot
A snippet with an entity (Person here) can be used inside a data view, list view or template grid with the same entity

Previously, you might have used the FormLoader custom widget for reusing parts of the interface. Snippets offer better performance and have the added benefit of actually showing you the contents of the snippet in places where you use it. Other use cases of the FormLoader have also been eliminated by Mendix 5: you can now use conditional formatting in template grids, list views and tooltip pages.

We want to highlight one final use case for snippets. Because layouts are intended to specify what comes where, we limit what kind of widgets can be inserted into them. For instance, data widgets, such as a data view, are not available for use in a layout. However, there can be use cases for having a data view in a layout, for example for showing the name of the current user. Since layouts can include snippets and snippets can include data widgets, we recommend including a snippet on a layout to address these use cases.

To summarize, snippets help you structure the user interface of your application and save development time by consolidating shared content in one place. Combine this with layouts and Mendix 5 offers a lot more power when designing your apps.

Next up, we will take a look at styling Mendix 5 apps.

Author Info

Arjan van IJzendoorn