xShirase
xShirase

Reputation: 12399

Variable dustjs partial name

I am setting up some heavy split testing using dust.js on my single page app.

The base template looks like (simplified):

{>"layouts/master" /}

{<body}
<div id="container">
  {?home}{>homeWelcome/}{/home}
</div>
{/body}

What I'm trying to do is have a folder containing N versions of the homeWelcome partial, and send N through the model to select the right template, like so :

{<body}
<div id="container">
  {?home}{>/splits/homeWelcome_{partialNumber}/}{/home}
</div>
{/body}

But it (unsurprisingly) doesn't compile.

I could send params to the one homeWelcome template, and have all my splits in there but some are radically different from the others and it'd make for one hell of a long file.

In addition to that, I want to be able to add/remove partials in the splits directory dynamically (partialNumber is a rand from 1 to the number of files in the dir).

Any ideas how to achieve that?

Upvotes: 0

Views: 207

Answers (1)

Interrobang
Interrobang

Reputation: 17434

Just add double quotes around the partial name and dust will happily parse the string before including a partial.

Note that partial names don't necessarily relate to folder structure, but I'm assuming you are compiling your templates with the appropriate names.

Upvotes: 2

Related Questions