Hi
This is my first time posting a question.
I’m relatively new to Skuid, especially to snippets. I’m sure this question has been asked and answered many times, but I haven’t found a definitive answer with an example. Hoping for a little clarification.
I have in-line snippets which make use of custom Javascript functions.
My first attempt at this had a function defined within the snippet itself.
The snippet would start with the usual:
var params = argumentsu0], $ = skuid.$;
In the body of my snippet I’d refer to the function:
var x = myFunction(this);
then at the end of the snippet I’d define the function itself:
function myFunction(parameter1) {
//code to be executed
}
This seems to work, but it makes sense for me to centralize such functions outside of the snippet. I then moved the function into a js file which I add as a Static Salesforce Reference (named ‘MyResource’ for this example).
Here’s where I’m a little unclear. I changed the first line of the js file to:
skuid.snippet.registerSnippet(“MySnippet”, function(parameter1) {
// function definition
});
Then in my skuid page I first add a Javascript resource of type Static Resource which points at this static resource. I then have my regular in-line snippet.
Within my in-line snippet I call:
var snippet= skuid.snippet.getSnippet(‘MySnippet’);
I was able to get this to work by then calling:
var x = snippet(this);
Just want to make sure this is the recommended way to accomplish this or if there’s simpler/better method?