0

I'm trying to abstract some code and would like to take advantage of dust.helpers to render a parial.

My current setup:

{> "includes/components/link" /}

My ideal setup:

{@uiComponent name="link" /}

My helper:

dust.helpers.uiComponent = function (chunk, context, bodies, params) {
    return dust.render('includes/components/' + name, context, function (err, out) {
        chunk.end(out);
    });
};

I have also tried a number of other things and nothing works.

And yes, I tried looking at the documentation. :(

Any advice would be much appreciated!

peduarte
  • 1,667
  • 3
  • 16
  • 24
  • Do you want to handle the partial in a special way or is this simply to abstract the file path away? – Interrobang Aug 14 '15 at 15:52
  • Mainly to abstract the path... currently! But want to have the possibility to manipulate data, if I need to, for example. – peduarte Aug 14 '15 at 15:57

1 Answers1

1

In Dust, helpers return Chunks, so you want to use Chunk methods to return out of your helper rather than dust.render.

In this case, you are working with partials, so you want chunk.partial:

dust.helpers.uiComponent = function (chunk, context, bodies, params) {
  var name = context.resolve(params.name);
  return chunk.partial('includes/components/' + name, context, params);
};
Interrobang
  • 16,984
  • 3
  • 55
  • 63