Search code examples
javascripttemplate-enginedust.js

Dust.js dynamic keys & sections


I am new to Dust.js. Is it possible for the latest version of dust.js to display value via dynamic keys or sections? If possible please show me how. If not possible, then how can we work on such condition using javascript with dust.js?

Thank you.


Solution

  • If you use LinkedIn's fork of dust then, yes, you can use dynamic variables. For the following context:

    {
        variable: 'one',
        object: {
            one: 'first variable',
            two: 'second variable'
        }
    }
    

    You can do the following in your template:

    {object[variable]}
    

    Which will print 'first variable'.