Reference a property + string in a single array item?
In an effort to templatize this plug-in inserting script, I'm running into an issue with these two bits of the code:
const pluginName = event.props.pluginName;
clickPopupMenu(popupMenu, [
["plug-in", pluginCategory, "${pluginName} (mono)"],
["multichannel plug-in", pluginCategory, "${pluginName} (stereo)"]
That was my best guess from some Google searching on using expressions in strings, but it's returning an error.
Is it possible to have the third item in those arrays output, eg. "FabFilter Pro-Q 3 (mono)"? (if that was the plug-in name the user entered in a preset).
- In reply tocooper⬆:Raphael Sepulveda @raphaelsepulveda2021-12-04 05:48:36.986Z
The first thing I noticed in your code was that you used regular quotation marks for the strings where you wanted to concatenate a string and a variable. These are called template literals and need to be wrapped in backticks ( ` ) for them to work properly! See below:
const pluginName = event.props.pluginName; clickPopupMenu(popupMenu, [ ["plug-in", pluginCategory, `${pluginName} (mono)`], ["multichannel plug-in", pluginCategory, `${pluginName} (stereo)`]
The other thing I don't see here is where the
pluginCategory
variable value is coming from. If that is also part of the template, make sure to bring it in just like you did withpluginName
.Tip: You can bring in multiple variables in one line like this:
const { pluginName, pluginCategory } = event.props;
This is called destructuring.
Finally, I'm not sure if you knew this but there's an excellent package in the store called Teezio's Plugin Loader which is highly developed. I'd suggest you check it out if you haven't already!