-
Notifications
You must be signed in to change notification settings - Fork 23
Your First Script
JavaScript-Expansions scripts are all written in JavaScript coding language (as the name implies).
Here is an example "Hello, world!" script:
function helloWorld() {
return "Hello, world!";
}
helloWorld();
As you can see, the scripts return one value.
NOTE: Semicolons (;
) are not required in JS language. However, this is required with multiple statements stacked in 1 line of script
To use our hello_world script, first let's save the above as hello_world.js
inside the plugins/PlaceholderAPI/javascripts/
folder.
Next, add it to the plugins/PlaceholderAPI/javascript_placeholders.yml
file so the expansion knows to load it!
NOTE: Specifying script engine is optional, as it will be defaulted to 'nashorn' if not initialized
hello_world:
file: hello_world.js
Then, after reloading with JS-Expansion command (/jsexpansion reload
) or PlaceholderAPI plugin (/papi reload
), you can use your placeholder!
To test it, run /papi parse me %javascript_hello_world%
(doesn't work in console)
And ta-da!
After you've learned the basics of placeholder scripts, head on over to Advanced Scripts to learn what you can fully do!