Lookup data from Handlebars template

Hello,

We're throwing around some different design ideas for a project and one of the ideas would require retrieving configuration data stored with the record from a Handlebars template. Thing XML template being saved to FTP server.

This configuration data is an array of essential key/value pair records, something like this:

{
"config": [{
"name": "supplierSKUId",
"value": "PW"
}, {
"name": "UOMQualifierID",
"value": "UOMQID"
}]
}

From our template, we'd like to do something like this:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<header>
<documentType>TransferOrder</documentType>
<timestamp>{{timeStamp 'UTC'}}</timestamp>
<UOMQualifierID>{{find "config", "name", "UOMQualifierID", "value", ""}}</UOMQualifierID>

That would yield

<UOMQualifierID>UOMQID</UOMQualifierID>

The signature of the helper would be:

{{find <array to search>, <path to property to search>, <value to search for>, <path to property to return>, [, <default value>]}}

That signature is getting a bit long, perhaps the find() helper could return an object and could be used in conjunction with a helper like getValue but one that took an object reference as a parameter, something like this:

<UOMQualifierID>{{getValue (find "config", "name", "UOMQualifierID") "value"}}</UOMQualifierID>

I'm sure if I thought about this longer I could think of more use cases and maybe some overloads to support those use cases, but you get the idea (hopefully) from this example.

 

My question: Is there a way to do this now?

Follow up question: If not, can we work with you to create this helper?

 

Regards,
Steve

0

Comments

5 comments
Date Votes
  • Hi Steve,

    There is no way currently to add custom helpers. I am unsure exactly what your output should be here, but would this handlebar work for you?

    {{#each config}}
    <{{name}}>{{value}}</{{name}}>
    {{/each}}

    0
  • Thanks for the reply Orion.

    I updated my post to so correct a missing parameter in my "find" helper examples, I also added a section on what I would expect to have returned. Your example will enumerate an array, I'm not looking for that, I want to find an object in an array and use one of it's properties in my template.

    0
  • Hi Steve, if that is the case, where you can't just take out the config XML elements from your template and list all the elements in order of the config array using the #each helper, which would make a this output:

    <supplierSKUId>PW</supplierSKUId>
    <UOMQualifierID>UOMQID</UOMQualifierID>

    If the above doesn't work for you, assuming this is for a custom flow and not an Integration App, you can add a JavaScript preMap hook to the import step to separate out the objects into the config array into their own key/value pairs, and use those directly in each corresponding element without a handlebar helper. There currently is no way to add a custom handlebar helper.

    0
  • Hi Orion,

    Thank you for the reply.

    I don't want to do this in script, I'm looking for a template only solution. Hopefully my post here will get some attention and there can be consideration for adding this helper or something like it.

     

    0
  • I believe these built-in helpers would also work for your use-case without needing a custom one, but I do also hope that at one point custom helpers will be configurable.

    <supplierSKUId>{{#each config}}{{#compare name '==' 'supplierSKUId'}}{{value}}{{/compare}}{{/each}}</supplierSKUId>
    <UOMQualifierID>{{#each config}}{{#compare name '==' 'UOMQualifierID'}}{{value}}{{/compare}}{{/each}}</UOMQualifierID>

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post