MagicMirror² DocsMagicMirror² Docs
Donate
Discord
Forum
GitHub
Donate
Discord
Forum
GitHub
  • Getting Started

    • Introduction
    • Requirements
    • Installation & Usage
    • Upgrade Guide
  • Configuration

    • Introduction
    • Autostart your MagicMirror²
    • Raspberry Specific
  • Modules

    • Introduction
    • Module Configuration
    • Default Modules

      • Alert
      • Calendar
      • Clock
      • Compliments
      • Hello World
      • News Feed
      • Update Notification
      • Weather Module
    • Animation Guide
  • Module Development

    • Introduction
    • The Core module file
    • The Node Helper
    • Rendering Component
    • MagicMirror Helper Methods
    • Logger
    • Notifications
    • Weather Module Weather Provider Development
    • How to write good documentation
  • Core Development

    • Introduction
    • Testing
    • Debugging
  • About

    • MagicMirror² Manifesto
    • Contributing Guidelines
    • Donate
    • Support
    • License

Rendering Component

There are two main approaches to rendering your component. Procedurally generating a Dom object with getDom, or using the built in Nunjucks templating engine.

With both approaches, rendering is first triggered when the module is first loaded. When your module's data changes, you can call this.updateDom() to trigger a re-render.

Using getDom

The getDom method is called by MagicMirror whenever it needs to update information on the screen. This method should return an HTML Element which contains all the information you would like to display.

Example:

getDom: function() {
	const wrapper = document.createElement("div");
	wrapper.innerHTML = 'Hello world!';
	return wrapper;
}

Using Nunjucks Templates

If getDom is not overridden, MagicMirror will try and render a Nunjucks template from getTemplate.

Nunjucks is a templating language for JavaScript. You can read more about the syntax in the Nunjucks Documentation.

Templates and Data

Templates are rendered by calling getTemplate to get the path to the template and getTemplateData to get the data used in the template.

Example:

MMM-MyModule.js

getTemplate: function() {
  return "MMM-MyModule.njk";
},

getTemplateData: function() {
  return {
    list: ["item 1", "item 2", "item 3"],
  };
}

MMM-MyModule.njk

<ul>
  {% for item in list %}
  <li>{{ item }}</li>
  {% endfor %}
</ul>

Rendered HTML:

<ul>
  <li>item 1</li>
  <li>item 2</li>
  <li>item 3</li>
</ul>

Filters

Nunjucks Filters are functions added to Nunjucks that can be applied to variables passed to the template.

translate filter

MagicMirror provides a translate filter which can be used to access the same functionality available in the this.translate module instance method.

{{ "INFO" | translate }}

Adding filters

You can add your own filters by accessing the Nunjucks environment via this.nunjucksEnvironment()

this.nunjucksEnvironment().addFilter("space", function (str) {
  return str.split("").join(" ");
});

For filter examples see the weather module.

Help us improve this page!
Last Updated: 10/25/25, 4:07 PM
Prev
The Node Helper
Next
MagicMirror Helper Methods