Link Templating with Javascript

The Link field is used for adding links to the web, to documents in your prismic.io repository, or to files in your prismic.io media library.

When integrating a Link in your repository, a link resolver is necessary as shown below. To learn more about this, check out our Link Resolving page.

Here's how to retrieve the url for a Link to the Web.

Copy
var PrismicDOM = require('prismic-dom');

PrismicDOM.Link.url(document.data.webLink, ctx.linkResolver)

Here's how to retrieve the url for a Link to a Document.

Copy
var PrismicDOM = require('prismic-dom');

PrismicDOM.Link.url(document.data.documentLink, ctx.linkResolver)

Here's how to retrieve the url for a Link to a media item.

Copy
var PrismicDOM = require('prismic-dom');

PrismicDOM.Link.url(document.data.mediaLink, ctx.linkResolver)