Utilizing handlebars.js, I have been employing {{#each}}
and {{#if}}
to extract data from JSON files. However, I am in need of a method to retrieve the data without any conditions. Since there is only one set of data available and no requirement for an {{#if}}
statement, using {{#each}}
seems unnecessary. Is there a simpler way to access a single block of data?
It is important to mention that I am utilizing Grunt with Handlebars and my document references more than just one JSON file.
Below is the code snippet:
{{data.PaymentMethod}}
<table>
<tr>
<td>
<div>Payment Method</div>
<div>Card Number: {{CardNumber}}</div>
<div>Card Colder: {{CardHolder}}</div>
<div><a href="{{Link}}">Tracking</a></div>
</td>
</tr>
</table>
Here is the content of my JSON file (data.json
):
{
"PaymentMethod": [
{
"CardNumber": "****",
"CardHolder": "John Doe",
"Link": "http://www.test.com"
}
]
}