使用Leaf时,如果if是,则else条件不能正确执行

时间:2018-12-28 12:29:38

标签: if-statement vapor leaf

我有一个简单的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>
}

然后会显示标题,但页面STILL仍显示为:

#else {Helloward}

我还尝试了各种语法,例如:

##else { <title> Hello World </title> }#else() { <title> Hello World </title> }甚至##else() { <title> Hello World </title> }

这似乎很基础,我相信我遵循了documentation

1 个答案:

答案 0 :(得分:4)

您的问题似乎是Leaf期望else,但是正在使用#else。因此,将模板更改为此可以解决问题:

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

这里是相关的documentation