Helping you drive digital innovation
Subscribe
RSS Feed of the Mendix Blog
Thanks for Subscribing

Keep an eye out for Mendix resources coming straight to your inbox.

Creating Maintainable Interfaces with Snippets

on March 28, 2014

Share:

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.

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.

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.

Subscribe to Our Blog

Receive Mendix platform tips, tricks, and other resources straight to your inbox every two weeks.

RSS Feed of the Mendix Blog
Arjan van IJzendoorn

About Arjan van IJzendoorn

Arjan is a member of the Mendix R&D department. He started developing the Mendix Modeler a long time ago and is still working on that application most of the time. Currently, he focuses on the modeling side of pages and widgets, with the occasional excursion into the rest of the Modeler.

| Community Profile
  • Snippets are what I was missing in version 4. I use them quite often in Mendix 5 now.
    Good examples, Arjan!