Search code examples
javascripthtmlnode.jsgruntjsdust.js

Render nested array of Hashmaps with the usage of "@select" in .dust file


I have JSON object containing the array of Hashmaps as:

{   "someparentkey": {
        "arraykey": [
            {
                "uniquekey": "key1",
                "content": "param1"
            },
            {
                "uniquekey": "key2",
                "content": "param2"
            }
        ]
    }
}

Based on each value of "uniquekey", I want to render the separate dust template with value of "content" passed to the imported dust template.

This is what my base template looks like right now:

{#someparentkey}
    {#arraykey}
        {@select key={uniquekey} }
            {@eq value="key1"}{>"path/to/dust1" param={content} /}{/eq}
            {@eq value="key2"}{>"path/to/dust2" param={content} /}{/eq}
            {@default}<!-- Invalid script tag {key} in configuration -->{/default}
        {/select}
    {/arraykey}
{/someparentkey}

And my imported templates ("path/to/dust1.dust" and "path/to/dust1.dust") are like:

<span>{param}</span>

But while doing the "grunt build" of the dust file, I am getting the error as:

SyntaxError: Expected end tag for arraykey but it was not found. At line : 3, column : 9 Blockquote

Warning: Dust.js failed to compile template "path/to/my/base-dust".

Questions:

  1. What's the issue in my current template code?
  2. And is there any better way to achieve what I want?

Solution

  • This is the template which I finally ended up using and it worked for me:

    {#someparentkey.arraykey}
        {@select key=uniquekey }
            {@eq value="key1"}{>"path/to/dust1" param=content /}{/eq}
            {@eq value="key2"}{>"path/to/dust2" param=content /}{/eq}
            {@default}<!-- Invalid script tag {key} in configuration -->{/default}
        {/select}
    {/someparentkey.arraykey}