Last active
November 14, 2016 19:55
-
-
Save michaelgodshall/d9e22ecaae4aded1722b3740c48c637f to your computer and use it in GitHub Desktop.
Prismic.io Homepage Custom Type Example
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
Prismic.API(config.prismic.endpoint, {accessToken: config.prismic.accessToken}, function (error, api) { | |
api.query(Prismic.Predicates.at('document.type', 'project'), {'fetchLinks': 'client.name'}).then( function (projects) { | |
ctrl.projects = projects.results; | |
api.query(Prismic.Predicates.at('document.type', 'homepage')).then( function (homepage) { | |
ctrl.homepage = homepage.results[0]; | |
// Header Projects | |
var headerProjects = ctrl.homepage.getGroup('homepage.header_projects').toArray(); | |
// Get the full Project object for this link | |
_.forEach(headerProjects, function (headerProject) { | |
ctrl.headerProjects.push(_.find(ctrl.projects, function (project) { | |
return project.id === headerProject.getLink('project').id; | |
})); | |
}); | |
// List Projects | |
var listProjects = ctrl.homepage.getGroup('homepage.list_projects').toArray(); | |
// Get the full Project object for this link | |
_.forEach(listProjects, function (listProjects) { | |
ctrl.listProjects.push(_.find(ctrl.projects, function (project) { | |
return project.id === listProjects.getLink('project').id; | |
})); | |
}); | |
}); | |
}) | |
}); |
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
{ | |
"Homepage" : { | |
"title" : { | |
"type" : "StructuredText", | |
"config" : { | |
"placeholder" : "Page Title", | |
"single" : "heading1" | |
} | |
}, | |
"header_projects" : { | |
"type" : "Group", | |
"fieldset" : "Projects to display in Homepage Header", | |
"config" : { | |
"repeat" : true, | |
"fields" : { | |
"project" : { | |
"type" : "Link", | |
"config" : { | |
"placeholder" : "Project", | |
"select" : "document", | |
"customtypes" : [ "project" ] | |
} | |
} | |
} | |
} | |
}, | |
"list_projects" : { | |
"type" : "Group", | |
"fieldset" : "Projects to display in Homepage List", | |
"config" : { | |
"repeat" : true, | |
"fields" : { | |
"project" : { | |
"type" : "Link", | |
"config" : { | |
"placeholder" : "Project", | |
"select" : "document", | |
"customtypes" : [ "project" ] | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment