Using Display Templates With the Node ASK SDK V2

Matty Williams
Oct 4, 2018 · 1 min read

If you want to make effective use of displays on Echo Dots and Echo Shows, display templates are essential.

Display templates allow formatting of text and images for your custom skills, supporting both body templates, that show information to the user, and list templates, that allow lists to be formatted and items to be selected.

The docs for the ASK SDK can be found here, and show that you can use the addRenderTemplateDirective() method to include a template. This method requires the template configuration to be passed, as shown below.

const template = {
type: 'BodyTemplate3',
backButton: 'HIDDEN',
image,
title,
textContent
};

The configuration may require an Image, and textContent. These can be mistaken for simple strings, but as shown by the docs, they have to be created via some nice helpers.

const Alexa = require('ask-sdk');const textContent = new Alexa.RichTextContentHelper()
.withPrimaryText(text)
.getTextContent();
const image = new Alexa.ImageHelper()
.withDescription('alexa image')
.addImageInstance(imageSrc)
.getImage();

Once these are constructed, pass them to your template configuration and add the template to your intents response.

And there you have it, displaying content to your users through an echo display, as well as through the power of speech.

Matty Williams
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade