string-template icon indicating copy to clipboard operation
string-template copied to clipboard

How to pass objects?

Open atulmala opened this issue 2 years ago • 1 comments

I have an object like this

let order = { owner: { firstName: "John", lastName: "Doe" } }

and this is my template

let template = "

hello {order.owner.firstName} {order.owner.lastName}

";

but the output is

hello {order.owner.firstName} {order.owner.lastName}

instead of

hello John Doe

does string-template not process objects those are passed? Or there is some other way to accomplish it?

atulmala avatar Jan 15 '23 06:01 atulmala

This package doesn't support nested access, it was designed to be a straight forward interpolated. If you want to use accessor notation consider https://www.npmjs.com/package/micromustache

Matt-Esch avatar Jan 17 '23 23:01 Matt-Esch