Custom display variants

Last updated:

This article explains how display variants in Formcentric can be used and individually extended. In addition to using predefined classes, it shows how to define custom variants and integrate them into the desired appearance via CSS or templates.

Using display variants

Many themes support display variants via classes, which can be applied to the markup from the Editor configuration.

Important basic rules:

  1. style_class is intended for additional CSS classes
  2. field_width is an independent property and should be used for width classes
  3. Comma-separated classes from the Editor are normalised to spaces at runtime


Common examples from the built-in themes:

  1. mwf-s, mwf-m, mwf-l for field widths
  2. mwf-separator for separator variants in supported themes
  3. fc-file__dashboard--inline and fc-file__dashboard--modal for file upload display variants

Creating and using your own display variants

To use your own display variants, you will need three things:

  1. A class or a variant assignment in the Editor
  2. A theme or CSS that actually evaluates this class
  3. Templates that pass the style_class to the matching DOM element (optional)


Defining the CSS class in the Editor

Specify a class in the Editor or in your field configuration, for example:

  1. my-highlight
  2. my-compact
  3. fc-file__dashboard--modal


Creating and including the CSS file

Step 1: Create the CSS file


Step 2: Include the CSS file in HTML or build

  1. Conventionally with a <link>
  2. In the framework via the normal CSS or SCSS import
  3. In a theme directly in the corresponding partial files

Step 3: Define CSS rules

Where possible, work against stable theme or wrapper classes and not against arbitrary DOM depths.


Adjusting specific elements

Recommendations for more precise adjustments:

  1. Open the browser’s developer tools
  2. Check the element actually rendered and its classes
  3. Evaluate whether the class ends up on the external field container or an inner wrapper
  4. Then target the CSS accordingly

In the case of file uploads or more complex fields, always check which element in the template receives the style_class.

Feedback