(Quick Reference)

r:script Tag

Using this tag you can write "inline" JavaScript code anywhere in your GSP (providing you use Sitemesh layouts) and be placed into either "head" or "defer" dispositions.

The code is executed after all the other resources in the given disposition have been included, so you can easily stack up little fragments that set up your UI elements or perform other functions.

This is perfect for custom taglibs that need to render bits of code inline according to their attributes.

Assuming a Sitemesh layout that calls <r:layoutResources/> at the correct times, the following causes alerts to occur when head and page body load:

<html>
   <head>
      <meta name="layout" content="main"/>
      <r:require modules="jquery-ui, blueprint"/>
      <r:require module="single-module"/>
   </head>
   <body>
       <r:script>
           window.alert('This is the end of the page!');
       </r:script>

<r:script disposition='head'> window.alert('This is the head of the page!'); </r:script> </body> </html>

Attributes

  • disposition - Optional. The disposition name of the code. Defaults to "defer", but the alternative is "head"