Random Quotes using the Templater and Admonitions plugins

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:

  1. Download the javascript file and place it in your Templater Scripts directory.
  2. Place the command tp.user.randomQuote() in your note template.

image

randomQuote.js (github.com)

6 Likes

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?

Cheers!

1 Like

This script pulls a random quote from a server and formats it.

Thee is a proposal for a plugin that handles your use case here: Embedding random quotes into notes - Plugins ideas

1 Like

Cheers Scott, I wouldn’t have found that without your link so I appreciate it.
Have replied on that thread, let’s see if it’s possible!

1 Like

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

Not sure what the issue is?

1 Like

Hi Jodine!

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.

Scott

1 Like

Okay great thanks for the feedback @ScottKillen ! It was driving mad trying to figure it out.

Do let us know if you find some other alternative. Thanks alot. :slight_smile:

1 Like

The service is working again.

1 Like

Oh okay! Thanks @ScottKillen :slight_smile: Might try using it again in the interim while I try setup my own local collection of quotes, to future-proof my workflows.

1 Like

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.

  1. Modify the JSON field names to suite the different payload
    quote = data.body;
  1. 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()  %> 
  1. 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}
...

Finally don’t forget to add the Admonition plugin

2 Likes

I posted the whole thing here

1 Like

I made some more tweaks and also turned into in a Templater Javascript Execution Command

In theory this is faster, but it could make your template harder to maintain

1 Like