Howto: Display table of results of Google Form

Part of my new website collects data from users, and then displays the results (think user reviews). Before starting the development with GoHugo, it was always my intention to incorporate Google Forms as the backend (simplicity, and utilizing the principle that if I cannot maintain or build it, it doesn’t happen).

So, I have just been playing around, and wanted to share how to do it.

  1. Create Google form and create some entries.

  2. In the Google form there will be a link to a google sheet. Click it.

  3. Go to File, and publish to web as csv. Make a note of the URL, as you will need it in a minute.

  4. Add this to your template (replace the csv url with your own):

         <table border="1">
             {{ $url := "" }}
             {{ $sep := "," }}
             {{ range $i, $r := getCSV $sep $url }}
             {{ if eq $i 0 }}
                 {{ range $r }}
                 <th>{{ . }}</th>
             {{ if ge $i 1 }}
                 {{ range  $r }}
                 <td>{{ . }}</td>
             {{ end }}

Of course, you can manipulate the data any way you wish, but being able to publish all the data in a table clearly is a great starting point.

1 Like

To highlight the code, use three `