The following:


define script() {

}

renders as:



Submitted by Sverre Rabbelier on 3 February 2011 at 22:13

On 4 February 2011 at 11:18 Danny Groenewegen commented:

The script tag is a special case of XML embedding, it allows you to insert Javascript instead of regular template elements. You can create such a script template this way:

application test

define page root(){
  script("alert('hello world!')")
}

define script(s:String){
  <script>
    ~s
  </script>
}

On 4 February 2011 at 13:27 Sverre Rabbelier commented:

That makes it bothersome to insert larger templates though (since they contain newlines). E.g.:


script {
" window.toggleEvents = function() {"
" jQuery(‘.eventContainer’).slice(3).each("
" function(idx) {"
" $(this).toggle();"
" })"
" }"
" jQuery(toggleEvents);"
}

Although even that still needs those quotes everywhere. What we really need I guess is JS embedding :P.

vs.:


script(“window.toggleEvents = function() { jQuery(‘.eventContainer’).slice(3).each(function(idx) { $(this).toggle(); }) } jQuery(toggleEvents);”)


On 4 February 2011 at 13:51 Danny Groenewegen commented:

We have JS embedding, your example gave me the impression that you wanted to work around it. Try this:

<script>
  window.toggleEvents = function() { jQuery('.eventContainer').slice(3).each(function(idx) { $(this).toggle(); }) } jQuery(toggleEvents);
</script>

On 4 February 2011 at 13:54 Sverre Rabbelier commented:

Ah, that is useful, but that still means means I have to write “”) every time? One thing I like about WebDSL is that I don’t have to worry about closing a tag properly, and don’t have to repeat stuff like type=… by using templates. Is there no way to solve that?


On 4 February 2011 at 14:14 Danny Groenewegen commented:

Currently you can only use literal javascript between <script> and </script>, but type="text/javascript" is added by default.

Log in to post comments