# String templates within string templates?

**URL:** <https://forums.losant.com/t/string-templates-within-string-templates/458>\
**Category:** Help\
**Created:** [March 21, 2017, 6:11pm UTC](https://forums.losant.com/t/string-templates-within-string-templates/458 "2017-03-21T18:11:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Martin](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/sam_martin/32/304_2.png) [@Sam\_Martin](https://forums.losant.com/u/Sam_Martin)\
**Post date:** [March 21, 2017, 6:11pm UTC](https://forums.losant.com/t/string-templates-within-string-templates/458/1 "2017-03-21T18:11:16Z")

</div>

I’m trying to make a skill for Amazon Alexa where she reads an array, but I’ve hit a roadblock. I want to implement a string template that looks like this: {{data.{{data.number}}.task.title}} However, I tried everything, but it won’t work! How can I make this happen?

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [March 23, 2017, 3:23am UTC](https://forums.losant.com/t/string-templates-within-string-templates/458/2 "2017-03-23T03:23:35Z")

</div>

Given a payload of …

```auto
{
  "indexToLookUp": 1,
  "data": [
    {
      "task": { 
        "title": "Title Zero"
      }
    },
    {
      "task": {
        "title": "Title One"
      }
    }
  ]
}

```

You can return “Title One” using the following string template:

```auto
{{#with (lookup data indexToLookUp)}}{{task.title}}{{/with}}

```

There are a few things going on here:

1. The [with block helper](http://handlebarsjs.com/builtin_helpers.html#with) shifts the string template’s context from the full payload object down to an object of our choosing for anything within the block.
2. The [lookup helper](http://handlebarsjs.com/builtin_helpers.html#lookup) allows us to return an array item by index. It takes two arguments: an array and an index. We pass it `data` from our payload and `indexToLookUp`, which is a number that is also on the payload.
3. Wrapping the lookup helper in parentheses treats it as a [subexpression](http://handlebarsjs.com/expressions.html#subexpressions), the result of which is what we pass as the argument to the “with” block helper.
4. Now, inside the “with” block helper, we can access the deep object property `task.title` as we normally would.

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [March 23, 2017, 3:14pm UTC](https://forums.losant.com/t/string-templates-within-string-templates/458/3 "2017-03-23T15:14:27Z")

</div>

Unfortunately handlebars isn’t very helpful when accessing data like this. An alternative approach could be to use a function node to move the data to a more accessible place on the payload.

```javascript
var index = payload.data.number;
payload.data.titleToRead = payload.data[index].task.title;

```

Then you can access it using the template:

```auto
{{ data.titleToRead }}}

```
