A Pen by Carlos Araya on CodePen.
Created
March 30, 2018 16:23
-
-
Save caraya/5d11e02f4b95e9e6a0c62d4366f03adf to your computer and use it in GitHub Desktop.
Handlebars Wordpress Demo
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
<div id="myContent"></div> | |
<template id="posts-list-template"> | |
{{#each posts}} | |
<div class="post"> | |
<h1>{{title}}</h1> | |
<div> | |
{{content.renderes}} | |
</div> | |
</div> | |
{{/each}} | |
</template> |
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
// https://wpdev.rivendellweb.net/wp-json/wp/v2/posts?per_page=10 | |
let myPosts = fetch('https://wpdev.rivendellweb.net/wp-json/wp/v2/posts?per_page=4') | |
.then((response) => { | |
return response.json(); | |
}) | |
.then((myJson) => { | |
console.log(myJson); | |
}) | |
.catch((err) => { | |
console.log('There\'s been an error getting the data', err); | |
}); | |
let template = document.getElementById('posts-list-template').innerHTML; | |
let renderPosts = Handlebars.compile(template); | |
document.getElementById('myContent').innerHTML = renderPosts({ | |
posts: myPosts | |
}); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.11/handlebars.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment