Skip to content

Instantly share code, notes, and snippets.

@LayneSmith
Created November 9, 2016 14:24
Show Gist options
  • Select an option

  • Save LayneSmith/bcdbde8567779e8335fb93f6edd3db2a to your computer and use it in GitHub Desktop.

Select an option

Save LayneSmith/bcdbde8567779e8335fb93f6edd3db2a to your computer and use it in GitHub Desktop.
Retrieve Google Spreadsheets content
function buildList(spreadsheet) {
$.getJSON("https://spreadsheets.google.com/feeds/list/" + spreadsheet + "/od6/public/values?alt=json", function (data) {
//Insert the hed and dek divs.
$('#listContainer').html('<div id="hed"></div><div id="deck"></div>');
//In console, you can see what info is being returned so you know how to get at the info you need. Remove for deployment.
//console.log(data);
//Find the total number of rows being delivered
var totalEntries = data.feed.entry.length;
//Creat an array where only the content you want will live
var contentArray = new Array();
//Add hed copy
var hed = data.feed.entry[0].gsx$text.$t;
$("#listContainer #hed").append(hed);
//Add dek copy
var deck = data.feed.entry[1].gsx$text.$t;
$("#listContainer #deck").append(deck);
//FOR loop parses the data and fills the array from above
for (var i = 2; i < totalEntries; i++) {
//Filling the array...
contentArray[i] = [data.feed.entry[i].gsx$link.$t, data.feed.entry[i].gsx$text.$t, data.feed.entry[i].gsx$credit.$t];
//jQuery: append the following string to the div with the class
$("#listContainer").append("<div class='box'><div class='number'>" + (i - 1) + "</div><img src=" + contentArray[i][0] + " width='100%'><div class='credit'>" + contentArray[i][2] + "</div><div class='textBox'>" + contentArray[i][1] + "</div></div>");
};
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment