0

I am loading (via requirejs) (the latest versions of) dust and dust-helpers in the following way

define.amd.dust = true;
require(["./Scripts/dust-full"], function (dust) {
    require(["./Scripts/dust-helpers"], function () {
        ... //my other dust custom helpers
    });
});

All works well - I am able to utilise the dust/dust-helper logic. But now I would like to leverage the dust-motes if helper and have tried the following

define.amd.dust = true;
require(["./Scripts/dust-full"], function (dust) {
    require(["./Scripts/dust-helpers"], function () {
        require(["./Scripts/dustmotes-if"], function () {
            ... //my other dust custom helpers
        });
    });
});
  • however - it gets to the "require(["./Scripts/dustmotes-if"], function () {" line and skips to the end (the closing curly brace) without going inside to execute "my other dust custom helpers". Note I have checked the file path to be OK.

I've also tried removing the "require(["./Scripts/dustmotes-if"], function () {" logic and replacing with simply "require(["./Scripts/dustmotes-if"]);" - although the code executes, the 'if' helper is not loaded into the helpers collection and hence referencing the 'if' helper in the dust code results in "Helper 'if' does not exist".

Has anyone tried this or have any ideas. The reference at http://www.dustjs.com/ doesn't really cover the above scenario - as well, much of the documentation/forum-posts online refer to old versions of dustjs and requirejs

TerrorBight
  • 334
  • 4
  • 23
  • 1
    It doesn't look like dustmotes-if supports being loaded via require(), it's just a simple IIFE that adds the helper to the `dust` object. – Interrobang May 12 '16 at 02:31
  • Thanks for the reply @Interrobang - if that is the case (i.e. it is not loaded via require) I'm still unclear how it is called - I've tried simply including the Javascript file and invoking the helper like: ... ... {@if test="1==1"}xxxx{/if} ... - but I still get "Helper 'if' does not exist. Are you able to provide an example ? – TerrorBight May 13 '16 at 08:00

1 Answers1

0

The issue was as @Interrobang suggested was that it should be loaded as an IIFE.

A few things to note

  • as the IIFE runs within it's own scope and required the dust object passed as a parameter, I assigned the dust object to the window object (see below)
  • the dustmotes-if referenced an old version of the dust library so it had to be changed - from "...require('dustjs-linkedin')..." to "...require('dust-full')...".

So the eventual code was as follows

...
define.amd.dust = true;
require(["./Scripts/dust-full"], function (dust) {
    require(["./Scripts/dust-helpers"], function () {
        window.dust=dust;
        $.getScript("./Scripts/dustmotes-if.js")
        .done(function(script,textStatus) {
            console.log(textStatus);
        })
        .fail(function(jqxhr,settings,exception) {
            console.log('Triggered ajaxError handler:'+exception.message);
        });
        ...

and in dustmotes-if.js

...
})(typeof exports !== 'undefined' ? module.exports = require('dust-full') : dust);
TerrorBight
  • 334
  • 4
  • 23