-
-
Save dindinet/5a7c3d605907d0e1585bdb77c731eae8 to your computer and use it in GitHub Desktop.
Fooling around with incorporating Airtable data into a Hugo site using getJSON. Started with some code from https://github.com/colinbate/for-sale/ and first just wanted to pull in data from another table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ $apiPrefix := "https://api.airtable.com/v0/"}} | |
{{ $key := getenv "AIRTABLE_KEY" }} | |
{{ if isset .Site.Params "view" }} | |
{{ .Scratch.Set "view" (printf "&view=%s" .Site.Params.view) }} | |
{{ else }} | |
{{ .Scratch.Set "view" "" }} | |
{{ end }} | |
{{ if isset .Site.Params "speakers_view" }} | |
{{ .Scratch.Set "speakers_view" (printf "&view=%s" .Site.Params.speakers_view) }} | |
{{ else }} | |
{{ .Scratch.Set "speakers_view" "" }} | |
{{ end }} | |
{{ $results := getJSON $apiPrefix $.Site.Params.base "/" $.Site.Params.table "?api_key=" $key (.Scratch.Get "view")}} | |
{{ $speakers := getJSON $apiPrefix $.Site.Params.base "/" $.Site.Params.speakers "?api_key=" $key (.Scratch.Get "speakers_view")}} | |
{{ range $results.records }} | |
{{ with .fields.Name }} | |
<h1>{{ . }}</h1> | |
{{end}} | |
{{ with .fields.Speakers }} | |
{{ range . }} | |
{{ $speakers_match := where ($speakers.records) "id" (string .) }} | |
{{ range $speakers_match }} | |
{{ with .fields.Name }} | |
<h2>{{ . }} </h2> | |
{{ end }} | |
{{ end }} | |
{{ end }} | |
{{end}} | |
{{ end }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment