Skip to content

Instantly share code, notes, and snippets.

// From the browser
var experimentCookie = prismic.startExperiment ? prismic.utils.docCookies.getItem('io.prismic.experiment') : null;
var experimentRef = experimentCookie ? api.experiments.refFromCookie(experimentCookie) : null;
var ref = experimentRef || api.data.master.ref;
<script>
// This is necessary for the edit button
window.prismic = {
endpoint: 'https://lesbonneschoses.prismic.io/api' // replace by your repository's endpoint
};
</script>
<script type="text/javascript" src="//static.cdn.prismic.io/prismic.min.js"></script>
// Example ref selection for NodeJS with ExpressJS
var ref = req.cookies[Prismic.previewCookie] || Api.master(),
// Example preview endpoint for NodeJS with ExpressJS
exports.preview = exports.route(function(req, res, ctx) {
var previewToken = req.query['token'];
ctx.api.previewSession(previewToken, ctx.linkResolver, '/', function(err, redirectUrl) {
res.cookie(Prismic.previewCookie, previewToken, { maxAge: 60 * 30, path: '/', httpOnly: false });
res.redirect(redirectUrl);
});
})
// Using Play Scala
val ref = queryRef orElse {
request.cookies.get(Experiment.cookieName) map (_.value) flatMap api.experiments.refFromCookie
} getOrElse api.master.ref
<!-- Prismic experiments, goes right after your Google Analytics script -->
<!-- Replace {googleId} by the GoogleId of the current experiment, using your template language -->
<script src="//www.google-analytics.com/cx/api.js?experiment={googleId}"></script>
<script src="//static.cdn.prismic.io/prismic.js"></script>
<script>prismic.startExperiment("{googleId}", cxApi);</script>
<!-- End of Prismic experiments -->
// Accessing image fields
fragments.Image.View imageView = doc.GetImageView("product.image", "main");
String url = imageView.Url;
# Accessing image fields
image = doc.get_image('product.image')
# By default the 'main' view is returned
url = image.url
# Accessing image fields
image = doc.get_image('product.image')
# Most of the time you will be using the "main" view
url = image.main.url