1

Consider the following dummy SSP file:

#{
    val testMap1 =  Map("a" -> true, "b" -> true, "c" -> true)
    val testMap2 =  Map("d" -> false, "e" -> false, "f" -> true)

    val something = true
    val value = 3
}#

<html>
<head>
<title>Test</title>
</head>

<body>

#if(something)
    <h1>True</h1>
#elseif(value > 2)
    <h1>False, but higher</h1>
#else
    <h1>False</h1>
#end


#if(testMap1.forall(_._2) && testMap2.forall(_._2))
    <h1>All true</h1>
#elseif(testMap1.forall(_._2) || testMap2.forall(_._2))
    <h1>One map true</h1>
#else
    <h1>Neither</h1>
#end

which is rendered by the following:

import java.io.File
import org.fusesource.scalate.{ TemplateSource, TemplateEngine }

val engine = new TemplateEngine()
val file = new File("path/to/file.ssp")

engine.layout(TemplateSource.fromFile(file))

This will fail.

The first if block will nicely execute, but the second if block will fail with some SyntaxError (Missing if at... or Cannot have more than one else at ...). I don't see any syntax difference between the two blocks. I'm bumping into this problem each time I generate booleans "on the fly" with some functional stuff. Am I not allowed to do this?

For instance, if I change the second block to the following, it does work:

#{
    val testMap1true = testMap1.forall(_._2)
    val testMap2true = testMap2.forall(_._2)        
}#

#if(testMap1true && testMap2true)
    <h1>All true</h1>
#elseif(testMap1true || testMap2true))
    <h1>One map true</h1>
#else
    <h1>Neither</h1>
#end

What is going on here?

Gx1sptDTDa
  • 1,558
  • 2
  • 11
  • 23

0 Answers0