Call a Snippet from HTML in a Template

  • 1
  • Question
  • Updated 3 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

  • 412 Points 250 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k 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>