Call a Snippet from HTML in a Template

  • 1
  • Question
  • Updated 4 years ago
  • Answered
Figured out how to call a js (inline) snippet from HTML in a template component:
<script>
var loadMoreFunc = skuid.snippet.getSnippet('loadMore');
</script>
<center><a href="javascript:loadMoreFunc();">Load More...</a></center>
My question is whether or not there is a more straight-forward way to do this?
This just seems unnecessary.
Any help is appreciated.  
Photo of Mark Tucker

Mark Tucker

  • 422 Points 250 badge 2x thumb

Posted 4 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,828 Points 20k badge 2x thumb
We'd reccomend a custom component,  or a custom renderer on one of our fields,  or a snippet bound to a regular skuid button. 
Photo of Mark Tucker

Mark Tucker

  • 422 Points 250 badge 2x thumb
Cool, thanks Zach. Tried getSnippet('loadMore') which didn't work, and I couldn't find documentation on get. Thanks!
Photo of Zach McElrath

Zach McElrath, Employee

  • 53,128 Points 50k badge 2x thumb
Official Response
Okay Mark my previous post actually didn't work. get() and getSnippet() do the same thing, one's just a shortcut for the other. The thing that was missing is that calling getSnippet() returns you a function. You have to actually invoke the function with () in order for it to do something. I get tripped up by that on occasion as well. So here's the correct version:

<center><a href="javascript:skuid.snippet.getSnippet('loadMore')();">Load More...</a></center>
Photo of Mark Tucker

Mark Tucker

  • 422 Points 250 badge 2x thumb
Awesome, thanks for the follow-up. I would have found that eventually, so thanks for saving me a minute. :-)