小编inc*_*ion的帖子

Swift Vapor Leaf 在变量中提供 html

我需要在 Swift Vapor 应用程序中创建一个复杂的 html 表。

问题是:Leaf 似乎不支持对 #(somevar += 1) 之类的变量进行计数,也不支持将 #(somevar1 + somevar2) 之类的字符串变量连接起来

所以我决定在应用程序中创建我的复杂表并将其传输到变量内的 html 模板。(在 php 中我一直都习惯这样做)

在模板中,我将变量称为

#(table) 
Run Code Online (Sandbox Code Playgroud)

但事实证明,当叶子转义所有变量时,我得到了纯 html 代码。

但是有 #raw() 函数可以打印出纯 html。

所以我做

<!DOCTYPE html>
<html lang="de">
<head><title>Server</title></head>
<body>
<..>

<form action="parameters" method="post">

// here is the thing: leaf gets a html table within the string 'table'.
// If I do it like that lead doesn't recognize #(table) as a leaf variable.
#raw( #(table) )

<button type="submit">Save</button>
</form>


</body>
</html>
Run Code Online (Sandbox Code Playgroud)

只是发现 #raw() …

html swift vapor leaf

5
推荐指数
2
解决办法
1185
查看次数

标签 统计

html ×1

leaf ×1

swift ×1

vapor ×1