Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
Inserting a variable into a string

I want to localize a json object by variable. For this I want to insert a html given variable into a json path as string.

I have a json file with a list of actors

"actors":{
    "Pete":{
      "status": "dead",
    },
    "Anna":{
      "status": "alive",
    },
    "Hans":{
      "status": "alive",
    },
    "Fred":{
      "status": "somewhat alive",
    }}

This file is used for foundryvtt as language file.

Now I want to access the data of the users by using the json path with their html handlebar.

{{localize 'actors.Pete.status'}}

which pushes the json path as string to a method which returns the json element.

This works perfectly and outputs: dead

Now I am trying to input a variable into the path. Which would look something like this:

{{localize 'actors.Variable.status'}}

My problem is, that the Variable is called similar as the json element:

{{user.name}}

which would output one of the names in the list, of course inputting this directly into the handlebar doesn't work.

{{localize 'actors.{{user.name}}.status'}}

I would love a simple and lightweight solution to this problem. Or some comments on my solution ;)

At the moment I am using some script with their java handlebar.

<input id="lan-name" name="name" type="text" value= "{{user.name}}" placeholder="Missing Translation for {{user.name}}"/>
<script>
   document.getElementById("lan-name").value = game.i18n.localize("actors.{{user.name}}.status");
</script>

But I only analyse code patterns and barely understand them. Happy about any comments and pointers. Thanks in advance :D

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!