Skip to content

Instantly share code, notes, and snippets.

@ScottJWalter
Last active January 25, 2024 09:45
Show Gist options
  • Save ScottJWalter/30c1f7f2ff2b951dc66f8b634902ad35 to your computer and use it in GitHub Desktop.
Save ScottJWalter/30c1f7f2ff2b951dc66f8b634902ad35 to your computer and use it in GitHub Desktop.
Script for Obsidian Templater plugin to simulate environment variables
/*
* emv.js -- A simple "environment variable simulator" for Obsidian Templater
*
* To use this from inside an Obsidian Templater script, drop this into the
* scripts folder (as defined in templater settings). Name it whatever you wish
* (Obsidian doesn't "namespace" javascript by file, it's all one global space).
*
* Now, inside your templater script:
*
* value = tp.user.env({ key: "key_name" });
*
* NOT case sensitive.
*/
// Put your key value pairs here
//
const env_array = [
{
key: 'key_1_name',
value: 'key_1_value'
},
{
key: 'key_2_name',
value: 'key_2_value'
}
/* ... ,{} ,{} ... and so on
];
// Nothing below this line needs to be changed
const env = parms => env_array.find(pair => pair.key.toLowerCase() === parms.key.toLowerCase()).value ?? "";
module.exports = env;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment