-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!-- DocSection: hello_world_index --> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Hello World with Kontent.ai</title> | ||
<script type="text/javascript" | ||
src="https://cdn.jsdelivr.net/npm/@kontent-ai/delivery-sdk@latest/dist/bundles/kontent-delivery.umd.js"></script> | ||
<script src="main.js" async defer></script> | ||
</head> | ||
<body> | ||
<!-- The HTML elements are there only to display data from Kontent.ai. | ||
Using JavaScript, you'll pull the content from your Kontent.ai project into the elements --> | ||
<img id="banner"> | ||
<h1 id="headline"></h1> | ||
<p id="bodytext"></p> | ||
</body> | ||
</html> | ||
<!-- EndDocSection --> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// DocSection: hello_world_main | ||
// Initializes the Delivery JS SDK | ||
var KontentDelivery = window['kontentDelivery']; | ||
|
||
// Creates a delivery client for retrieving data from Kontent.ai | ||
const deliveryClient = new KontentDelivery.createDeliveryClient({ | ||
// Tip: Use your project ID to display your own content. | ||
projectId: '8d20758c-d74c-4f59-ae04-ee928c0816b7' | ||
}); | ||
|
||
// Retrieves the content item | ||
deliveryClient | ||
.item('hello_headless_world') | ||
.elementsParameter(['headline', 'body_text', 'picture']) | ||
.toPromise() | ||
.then((response) => processData(response)); | ||
|
||
// Processes the retrieved data and displays it on the page. | ||
function processData(response) { | ||
const bodyText = response.data.item.elements.body_text.value; | ||
const headline = response.data.item.elements.headline.value; | ||
const picture = response.data.item.elements.picture.value[0].url; | ||
|
||
document.getElementById("bodytext").innerHTML = bodyText; | ||
document.getElementById("headline").append(headline); | ||
document.getElementById("banner").src = picture; | ||
} | ||
// EndDocSection |