使用Leaf,如果条件为真则执行if语句块,但是else语句块没有正确执行。

3

我有一个简单的Leaf模板,想要显示“Hello World”。

#if(false) {
<title> All hail Apodron.</title>
} #else {
<title> Hello World </title>
}

这个页面没有标题,显示内容如下:

#else {Helloward}

但是,如果我将其更改为:

#if(true) {
<title> All hail Apodron.</title>
} #else {
<title> Hello World </title>
}

然后标题确实显示了,但页面仍显示为:#else {Helloward}。我还尝试了各种语法,例如:##else { <title> Hello World </title> }#else() { <title> Hello World </title> } 甚至是 ##else() { <title> Hello World </title> }。这似乎非常基础,我相信我遵循了文档

蒸汽控制台提供任何有用的信息吗? - Kheldar
服务器正在 http://localhost:8080 上启动。是否有更详细的模式? - YannickR
1个回答

4

看起来你的问题是 Leaf 模板期望使用 else,但你使用了 #else。因此,将你的模板更改为以下内容即可解决该问题:

#if(false) {
  <title> All hail Apodron.</title>
} else {
  <title> Hello World </title>
}

这里是相关的文档。点击链接查看

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接