Created
September 20, 2017 17:54
-
-
Save deanebarker/c7c35cbea1a97d21394a67141aa15b5e to your computer and use it in GitHub Desktop.
An extension to show content items that are linked to the current item.
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
<html> | |
<head> | |
<link href="https://contentful.github.io/ui-extensions-sdk/cf-extension.css" rel="stylesheet"> | |
<script src="https://contentful.github.io/ui-extensions-sdk/cf-extension-api.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.1/mustache.min.js"></script> | |
<style> | |
body { | |
margin: 0; | |
color: #8091a5 !important; | |
overflow: hidden; | |
} | |
p { | |
margin-top: 0; | |
margin-bottom: 1em; } | |
ul { | |
padding-left: 2em; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="content"></div> | |
<script id="template" type="x-tmpl-mustache"> | |
<p> | |
There are {{terms.length}} term(s) linked to this chapter. | |
</p> | |
<ul> | |
{{#terms}} | |
<li><a title="{{fields.synonyms.en-US}}" href="/spaces/{{sys.space.sys.id}}/entries/{{sys.id}}" target="_blank">{{fields.title.en-US}}</a></li> | |
{{/terms}} | |
</ul> | |
</script> | |
<script> | |
window.contentfulExtension.init(function (extension) { | |
extension.space.getEntries({ | |
'content_type': 'term', | |
'order': 'fields.title', | |
'fields.chapters.sys.id': extension.entry.getSys().id, | |
'locale': 'en-US' | |
}).then(function(results){ | |
console.log(results.items[0]); | |
var rendered = Mustache.render(document.getElementById('template').innerHTML, {terms: results.items}); | |
document.getElementById('content').innerHTML = rendered; | |
extension.window.startAutoResizer(); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment