Mithril

Building an app in Drupal's theme layer

Submitted by swim on Thu, 11/05/2015 - 11:30

Drupal 8 as many people have already pointed out provides a great base for front end developers regardless of your chosen stack. Providing REST as core functionality has created a standardised approach which when left up to contrib can often become enigmatic.

This article aims to explain the benefits of building a JavaScript application via Drupal's theme layer. Mithril JS will be used as the client side framework, however the core concepts could be applied to others as well. 

Requests to Drupal can also be queued, allowing access to an array of results. This generally makes for more performant and organised code.


var nodes = md.queue([
  {
    method: 'GET',
    url: '/node/1',
    background: true
  },
  {
    method: 'GET',
    url: '/node/2',
    background: true
  },
  {
    method: 'GET',
    url: '/node/4',
    background: true
  }
]);

Bringing all of the above together I have made a very rough version of the classic Bartik theme. The example theme/site is located here.

While these are some nice examples they are very simple and lack (any) finesse, a problem only love can solve (more time). Hopefully over the coming months I'll have the opportunity to utilize these tools in more projects.

Subscribe to Mithril