2.1.0 • Published 2 years ago
prismic-element v2.1.0
prismic-element
Mimics prismic-dom except that it renders real DOM nodes and not just HTML strings.
NOTE:
Requires version 2 of the Prismic.io API and the compatible JavaScript library prismic-javascript.
Usage
Pass a rich text object to the function and get HTML Element(s) back.
const Prismic = require('prismic-javascript')
const asElement = require('prismic-element')
Prismic.api('https://<YOUR_API_ENDPOINT>.cdn.prismic.io/api').then(api => {
api.getSingle('my-page').then(doc => {
document.body.appendChild(asElement(doc.data.body));
})
})
With bel
Working with DOM elements integrates beautifully with tools such as bel and choo.
const html = require('bel')
const Prismic = require('prismic-javascript')
const asElement = require('prismic-element')
Prismic.api('https://<YOUR_API_ENDPOINT>.cdn.prismic.io/api').then(api => {
api.getSingle('my-page').then(doc => {
document.body.appendChild(html`
<article>
${asElement(doc.data.title)}
<figure>
${asElement(doc.data.image)}
<figcaption>${doc.data.image.alt}</figcaption>
</figure>
<hr />
${asElement(doc.data.body)}
</article>
`)
})
})
See also
- Prismic.io – CMS as a service
- bel – Create DOM elements using tagged templates
- choo - High level framework using tagged templates
License
MIT
2.1.0-1
2 years ago
2.1.0-0
2 years ago
2.1.0
2 years ago
2.0.5
3 years ago
2.0.4
4 years ago
2.0.3
5 years ago
2.0.2
5 years ago
2.0.1
5 years ago
2.0.0
5 years ago
1.0.0
6 years ago
0.7.1
6 years ago
0.7.0
6 years ago
0.6.0
6 years ago
0.5.0
7 years ago
0.4.0
7 years ago
0.3.3
7 years ago
0.3.2
7 years ago
0.3.1
7 years ago
0.3.0
7 years ago
0.2.2
7 years ago
0.2.1
7 years ago
0.2.0
7 years ago
0.1.1
7 years ago
0.1.0
7 years ago