Call snippet from snippet

Moshe KarmelMoshe Karmel Member
edited June 25 in Questions
So I have a whole bunch of snippets out there, and I've been thinking about consolidating some of them into library methods that are contained in a static resource. Firstly are there any performance implications by including snippets in a resource? What are the best practices for doing this? Also I got the static resource working with register snippet, and I can get the snippet with getSnippet. I understand that I can call it with something like:
var i = skuid.snippet.getSnippet('getCorrectURLIfPortal');
but how can I set the arguments for the snippet? Do I pass them into the apply function?


  • Moshe KarmelMoshe Karmel Member
    edited December 2014
    Anyone know the answer... ?
  • Rob HatchRob Hatch Skuad ✭✭
    edited September 2016
    Sorry for the delay, Moshe - we'll get back to you tomorrow. 
  • Moshe KarmelMoshe Karmel Member
    edited June 25
    Hey Rob I just had to bump this up before I fell off the front page :). #Impatient
  • Pat VachonPat Vachon Member ✭✭
    edited October 2016
    If I did that, the whole first page would be filled. *Smiling ear to ear*
  • Moshe KarmelMoshe Karmel Member
    edited December 2014
  • JD BellJD Bell Skuad ✭✭
    edited March 2018
    To answer the first part of your question - there is no performance hit. In fact, your page will be (ever so slightly) more performant by putting your snippets in a static resource (since it reduces the overall size of your page and the browser can cache the static resource).
  • edited January 2015
    Snippets can have arguments?? I've searched for 'snippet parameters' and found this.
    // If your snippet expects comma-separated parameters...getCorrectUrlSnippet(line1,line2,line3);
    I would LOVE to have arguments.  I have 4 snippets which could be one snippet if I could pass a parameter from an action.  Ideally, the merge syntax would translate the action snippet name first, then call the snippet, but I've be very happy with just straight parameters.

    Then if this would work with static resource snippets I wouldn't have the same snippet scattered all over pages.

  • Zach McElrathZach McElrath Skuad
    edited December 2016
    Seth, I'm assuming you're referring to wanting to pass parameters / arguments to Snippets called from a Step within the Action Framework? That a great idea.
  • edited February 2015
    Yes, absolutely.  Snippet parameter would open many, many doors. I hadn't mentioned it because I figured it was on the 'future' list already.  

    If you could use the merge-template with it, it would be STUPENDOUS!

    I see two methods, roughtly corresponding to a by-value parameter:
    This would obviously evaluate {{}} before passing that value as a parameter.  Now if that passes an object instead of the value...

    And a  'by reference' parameter:
    By reference is really a string, just need to be able to somehow 'de-reference' it in the snippet so it foo can update 'bar' easily.  Not sure what that would look like. Still new to skuid and snippets/javascript.

    But with this, I could have my stock routines as static resources and call them from many pages.  My initial use case is for convenience buttons to increment a date field by xx number of days. (theres an action for that, but the 'Next N Days' is currently not working so you need snippets as a workaround.

    Since JS is interperted (??), would it be possible to pass js code to a snippet as a parameter, that the snippet could run? Think similar to a sort routine where you pass a compare function.  Getting off into the weeds a bit... 
  • Pat VachonPat Vachon Member ✭✭
    edited January 2016
    Yup. I'm starting to get to this point where I need to snippets that can behave differently ever so slightly. Right now, I have to create and manage multiple versions of essentially the same code.
  • Matt SonesMatt Sones Member ✭✭
    edited February 2017
    Point of clarification:

    If I need to pass values that are not in the (arguments) to a snippet that I've stored in a static resource, I will need to create an inline snippet on the page to pass that value to my stored snippet?
  • Rob HatchRob Hatch Skuad ✭✭
    edited September 2016
    Matt,  I don't think that woudl be required. Your stored snippett can access the full Skuid API to retrieve model and component information. 
  • Matt SonesMatt Sones Member ✭✭
    edited December 2016
    Haha. Yep!

  • edited August 2016
    like... Like.... LIKEEEE Thanks Zazh!! Spelling it out help so much for a javascript noobie like me.
  • edited February 2017
    I just use this:
    skuid.snippet.getSnippet('exampleSnippet')(arg1, arg2, arg3);
  • Matt SonesMatt Sones Member ✭✭
    edited December 2016
    Yes. But I believe we're looking to be able to include arguments for our snippets declaratively in the builder.
  • SnehaSneha Member
    edited March 2019
    Awesome that the snippets of page includes can be called!! :)
  • Arne-Per HeurbergArne-Per Heurberg Member ✭✭
    edited March 2019
    SOOO helpful. just saying. Thanks!!
Sign In or Register to comment.