Skip to content

Instantly share code, notes, and snippets.

@wezell
Created April 2, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wezell/01b751637cd76ba87818 to your computer and use it in GitHub Desktop.
Save wezell/01b751637cd76ba87818 to your computer and use it in GitHub Desktop.
Simple custom field example
## This example uses a custom field that is called "test" and has the variable name "test"
## first we get the content (we have access to all our
## velocity tools, including any custom ones that have been written
#set($content = $dotcontent.find($request.getParameter("inode")))
## then we write some ugly js to get and set the values on the edit content form -
## the dom.id of the hidden field that stores the value is just the velocity variable name
## so watch out for js variable scope issues
<script>
function myButtonClick(){
var x = document.getElementById('test').value;
if(x==undefined || x.length==0){
x=0;
}
else{
x=parseInt(x)+1;
}
document.getElementById('test').value=x;
document.getElementById('customValue').innerHTML=x;
}
</script>
## then we write out our user controls, displaying the value stored in the content object by default
## with a button (dojo styled) that calls our js
Custom Value: <span id="customValue">$!content.test</span> &nbsp;&nbsp;&nbsp;
<button dojoType="dijit.form.Button" id="myButton" onclick="myButtonClick">Click me!</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment