These are the steps to create a function (tp.user.randomQuote()) that will insert a random quote inside a randomly-colored Admonition when the Templater plugin generates a note from a template:
Download the javascript file and place it in your Templater Scripts directory.
Place the command tp.user.randomQuote() in your note template.
Thanks Scott, this looks excellent and just what I’m looking for. I have a large document of quotes and I’d love to add a function to my daily notes that throws up a different one of my quotes each day - would that be possible with this particular script?
This will be really useful @ScottKillen , because I don’t like the daily quote function built into templater as I create my daily notes for the week ahead and want a different quote in each note.
I have placed your script into a folder called “scripts”. I have allocated that folder in the Templater settings. But when I insert a template with <% tp.user.randomQuote() %> in it, I get an error message:
Failed to load resource: net::ERR_NAME_NOT_RESOLVED
(unknown) Template parsing error, aborting. Failed to fetch
log_error
I ran into this, too, a few days ago. The “quotable.io” site which provides the quotes seems to no longer exist.
I performed a domain lookup and the domain is no longer registered. I can’t find any news about what happened, but it is obvious that the service has been discontinued.
This is unfortunate because it was a great service. I will post here if I find an alternative.
Edit: I should have also mentioned that the error message means that you set everything up correctly.
Oh okay! Thanks @ScottKillen Might try using it again in the interim while I try setup my own local collection of quotes, to future-proof my workflows.
Thanks for this. Exactly what I needed. I did modify it slightly to use a different quote API. I’ll explain the changes I made in case it helps other people.
Modify the JSON field names to suite the different payload
quote = data.body;
Optionally change the function name so it’s slightly more descriptive.
async function stoic_quote() { ...
module.exports = stoic_quote;
then call as
<% tp.user.stoic_quote() %>
Optionally bring the title out so it’s more obvious where to change it
const title = "Stoic Quote of the Day";
....
return `\`\`\`ad-quote
title: ${title}
color: ${red}, ${green}, ${blue}
...