Menu icon Foundation
Using JSON in Foundation Pages

I'm trying to use data stored in "company.json" in a page, but can't get it working. It would be nice to have access to single values stored in the JSON without a loop or the each command.

The JSON

{
  "company": [
    {
      "name_short": "Name",
      "name_long": "Name GmbH & Co. KG",
      "name_title": "Name - Firma für Services",
      "description": "Toller Serivce an allen Standorten",
      "url": "www.firma.de",
      "email": "[email protected]"
    }
  ]
}

The HTML

  <title>{{company.name_title}}</title> 


Probably a very basic question, but I'm new to this so no idea :) Happy for any help


Thanks in advance!

 

 

s

JSON

I'm trying to use data stored in "company.json" in a page, but can't get it working. It would be nice to have access to single values stored in the JSON without a loop or the each command.

The JSON

{
  "company": [
    {
      "name_short": "Name",
      "name_long": "Name GmbH & Co. KG",
      "name_title": "Name - Firma für Services",
      "description": "Toller Serivce an allen Standorten",
      "url": "www.firma.de",
      "email": "[email protected]"
    }
  ]
}

The HTML

  <title>{{company.name_title}}</title> 


Probably a very basic question, but I'm new to this so no idea :) Happy for any help


Thanks in advance!

 

 

s

Brandon Ellis Cranmore over 2 years ago

I was struggling with this as well, here is one way to do this, by accessing the id: 

<title>{{ company.0.name_title }}</title>

Also, you may want to remove the "company" wrapper and just use the array, otherwise you would need to call it like so:

<title>{{ company.company.0.name_title }}</title>

 

Hope this helps!

Michelle Child almost 2 years ago

Thank you ! I had the same question and could not find an answer anywhere. I was forgetting the [0] for the object inside the array.