DustJS: Render partial via a Helper

334 views Asked by At

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!

1

There are 1 answers

2
Interrobang On BEST ANSWER

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);
};