How do you create a function in jelly?

mahudg2
Kilo Expert

I have a content block and I'm used to using hyperlinks to call functions in my client script from a UI page like so

 

<a href="#" onClick="testFunction">Click Here</a>

 

however in a content block I no longer have access to the client script, and simply putting functions inbetween <script> tags does not work. I assume I would have to use jelly to perform this task but I'm kind of at a loss.

 

Does anyone have any ideas?

3 REPLIES 3

peterwestergaar
Kilo Expert

Sorry this is such a late reply Matt, but perhaps someone searching the forums might find some help.   (The way I was browsing through the forum archives looking to up my own "UI page" game).  



Anything you place in the "client script" section of a UI Page is client-callable javascript, the same as if you'd kept it in the HTML section in <script> tags.



So, if I put, in the HTML section:


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


        <a href="#" onClick="tryitout()">Click Here</a>


</j:jelly>



and in the Client script section:


function tryitout( ) { 


    alert('Hello, World');


}



Then my UI page will contain a link: "Click Here" which, when clicked, calls the client javascript function "tryitout", and pops an alert that says "Hello, World".



I think that's what you were looking to do?


ChrisBurks
Mega Sage

You mentioned a content block. Which type of content block? It won't work in a Static HTML block but should work in a Dynamic Content Block.


Here's a modified version of Peter Westergaard's example in a Dynamic Content Block placed on a CMS page:



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<div style="width:300px; margin: 50px auto; text-align: center">


<fieldset>


<legend>I am in a Dynamic Content Block</legend>




<button onclick="thisWorks()">Click me</button>


</fieldset>


</div>


<script>


function thisWorks(){


alert("This Works!");


}


</script>




</j:jelly>



Screenshot 2014-09-11 at 8.02.33 AM.png


cwmurphy
Mega Expert

There is a YouTube channel called TechNow that is done by Chuck Tomasi and Andrew Kincaid from ServiceNow.   The first three episodes are all about Jelly.   Definitely worth watching: TechNow Episode 1 | ServiceNow Jelly Scripting Part 1 of 3 - YouTube