Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8350363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:17:40+00:00 2026-06-09T08:17:40+00:00

This question is about using the dust.js templating system with paths to data in

  • 0

This question is about using the dust.js templating system with paths to data in sub-contexts. My intention is to support i18n using a map of keys to strings.

Given data like this:

{i18n : { firstname : "First Name" },
 people : [
    {"name" : "Moe"},
    {"name" : "Curly"}
 ]}

In dust you can use sections to list each person:

{#people}
    {name}
{/people}

And you can use a path to get access to the firstname i18n string:

{i18n.firstname}

But the following does not work:

{#people}
    {i18n.firstname}: {name}
{/people}

In fact, the documentation specifically says:

To avoid brittle and confusing references, paths never backtrack up
the context stack. If you need to drill into a key available within
the parent context, pass the key as a parameter.

So I try and pass the key as a parameter:

{#people i18n=i18n}
    {i18n.firstname}: {name}
{/people}

But this doesn’t work. When I experiment with this on the dust homepage, I see the compiled template has this code:

"i18n": ctx.get("i18n")

Which makes me think the above example should work fine.

So what gives? How can I make this work?

Note: The following does work:

{#people firstname=i18n.firstname}
    {firstname}: {name}
{/people}

But this doesn’t work well if you need to access a lot of i18n keys within the people context.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:17:41+00:00Added an answer on June 9, 2026 at 8:17 am

    Paths can be used in keys and in sections to specify where you want Dust to look for keys. To understand how and when to use paths, you should first understand how Dust looks for keys when there are no paths. You might want to sit down.

    When searching for keys, Dust first looks in the current context, then looks in each parent context until there are no more parents to search in. If no key is found, Dust does nothing (unless you are using an Exists or Not Exists Section). If Dust finds the key, it stops searching and uses the given value. That’s not too foreign, right? That’s how JavaScript looks for variables in execution environments.

    However, instead of looking up the tree toward root, when a path is used, Dust only looks at children. This is best illustrated with an example.

    JSON:
    
    {
      "i18n": {
        "firstname": "First Name"
      },
      "name": "My Dust Template",
      "firstname": "Surprise!",
      "people": [
        {
          "name": {
            "firstname": "Moe",
            "lastname": "Howard"
          }
        },
        {
          "name": {
            "firstname": "Curly",
            "lastname": "Howard"
          }
        }
      ]
    }
    

    And the Dust:

    Dust Template:
    
    {! Show the name of the template !}
    {name}{~n}
    {#people}
    
      {! 
         As you noted, the following will not work, because 
         when using a path, Dust only searches
         deeper into the JSON. The output will be:
         ": Surprise!"
      !}
      {i18n.firstname}: {firstname}{~n}
    
      {!
         To get your i18n string, you need to look up the 
         stack instead of down. This can be done by using a
         section without a path, as follows. The output will be:
         "First Name: Moe"
         "First Name: Curly"
      !}
      {#i18n}{firstname}{/i18n}: {name.firstname}{~n}
    
      {! 
         Note that we successfully used the path to 
         get the firstname of each of the people.
      !}
    {/people}
    

    [EDIT]: For more info, check out this wiki page from the LinkedIn fork of Dust: https://github.com/linkedin/dustjs/wiki/Where-else-does-Dust-search-if-the-value-is-not-defined%3F-A.K.A.-Dust-Scoping

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question about using the system-drawables in an Android-app some time ago:
This question talks about using the system command and passing variables. Here is an
This is a general question about using Ajax on data that is not text/string.
I have seen this question about deploying to WebSphere using the WAS ant tasks.
This question came about because the cells gem specifies template directories using File.join('app','cells'). That
This is a question about the VB.NET language. Since I am using it every
Although using daily in my programming , but never realized about this question :
This is a general question about character encoding when using MD5 libraries in various
This is not a question about a specific framework. I am using plain php
I think this is a moderately neophyte question. I've been using NHibernate/FluentNHibernate for about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.