Can't create script template, elements() taken literally
The following:
define script() {
}renders as:
Submitted by Sverre Rabbelier on 3 February 2011 at 22:13
Issue Log
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> }
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);”)
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>
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?
Currently you can only use literal javascript between
<script>
and</script>
, buttype="text/javascript"
is added by default.
Log in to post comments