Creating a templater variable for a dataview script

Using the examples in the github issue and your DataView script, I put together the following Templater template. I cannot test it since I don’t currently use the DataView plugin, but it should put you in the ballpark.

<%*
const dv = this.DataviewAPI;

// List of writing prompts
let prompts = [];

// Extract writing prompts from pages that have them
dv.pages("#wp")
	.forEach(page => {
		dv.array(page.writing_prompt)
			.forEach(writing_prompt => {prompts.push(writing_prompt);})});

let prompt = prompts[Math.floor(Math.random()*prompts.length)];
-%>
writing_prompt:: <% prompt %>
2 Likes