Eduardo Garcia bio photo


Eduardo Garcia

Knowmad by definition

Location: Australia

Twitter Facebook  QQ交谈 Google+ Github LinkedIn Feed

Backbone.Drupal is a standalone plugin to connect Marionette JS and Backbone JS applications with Drupal 7

Inspired in JS files from Drupal Module


$ git clone


Cross-origin: Enable to have Drupal as Backend in a Domain and the Backbone/Marionette App in other domain

In your Drupal Server you must setup HTTP Access Control to enable connection, below and example.


You must change the origin to use the domain you are using to run your application.

I strong recommend to use the Drupal module CORS to configure the HTTP Access Control

Authentication: Option login with Drupal user account to enable to execute REST operation PUT, DELETE, ADD. If Cross-origin is enabled login is required for GET operations.

Models: Created Backbone models for Nodes, Users, Comments Entities

You can add extra fields to modules to use as extra information in you application, these extra fields could be mark as noSaveAttributes. Check the following example.

var Property = Backbone.Drupal.Models.Node.extend({
      initialize : function(options) {
        // Setting the Id Attribute for Drupal model
        this.attributes.nid = options.property_id;
        this.noSaveAttributes = ['property_id'];

        // Extended Backbone.Drupal.Models.Node to my own service for Drupal Nodes.
        // This Rest service return absolute URL for field pictures
        this.urlSource = "node_waterbed";

Collections: Created Backbone collection for Users, Nodes and Views

REST: Integration with Services Server type REST


  • Implement Collections for Taxonomies and Search
  • Create integration with module Restws
  • Create version of plugin for Drupal 8.


<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <title>Backbone Drupal Library</title>
    <script src="./jquery.js"></script>
    <script src="./underscore.js"></script>
    <script src="./backbone.js"></script>
    <script src="./backbone.drupal.js"></script>
    <script src="./"></script>
      $(function() {
        // Set API Information
        Backbone.Drupal.restEndpoint = {
          root: 'http://onthisday/api',
          dataType: '.json'
        // Define auth object, set crossDomain if is necessary
        var Auth = new Backbone.Drupal.Auth({crossDomain: true});
        // Request executed in sync mode
        // If status is token further ajax will use the proper token
        var auth_status =  = Auth.login('admin', 'admin');

        if(auth_status) {

          // Check user retrieve

          var User = new Backbone.Drupal.Models.User({uid: 1});
            success: function (user) {
              // Check information retrived, could be used directly in a template

          //  Check users retrive

          var Users = new Backbone.Drupal.Collections.UserIndex();
            success: function (users) {
              // Check information retrived, could be used directly in a template
        } else {
          alert('Auth Error');



Note: This plugin could be used with RequireJS.