- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我需要在 Swift Vapor 应用程序中创建一个复杂的 html 表格。
问题是:Leaf 似乎不支持像 #(somevar += 1) 这样的变量计数,也不支持像 #(somevar1 + somevar2) 这样的连接字符串变量
所以我决定在 App 中创建我的复杂表格并将其传输到变量中的 html 模板。 (在 php 中,我一直习惯这样做)
在模板中我会这样调用变量
#(table)
但事实证明,我得到的是纯 html 代码,因为 leaf 转义了所有变量。
但是有 #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>
只是发现 #raw() 不查找变量,而只是打印出 {} 之间未转义的内容。所以我仍然进入网站“#(table)”而不是复杂的 html 表格。
所以现在我卡住了。如何将 App 生成的 html 代码作为 html 放入模板中?
可能我做错了。我如何在叶模板中获取 html 代码?还是我必须自己发送整个页面,作为带有 header 的 http 流……?
提前致谢,汤姆
最佳答案
更新
自 Vapor 3 以来 #raw(<var>)
默认情况下,标记未嵌入 --template=web
在创建 Vapor Leaf 项目时。我必须在我的 configure.swift
中手动注册它文件:
/// Leaf add tags
services.register { container -> LeafTagConfig in
var config = LeafTagConfig.default()
config.use(Raw(), as: "raw") // #raw(<myVar>) to print it as raw html in leaf vars
return config
}
https://docs.vapor.codes/3.0/leaf/custom-tags/
此外,如果有人正在寻找可用标签的完整列表,您可以简单地搜索 TagRenderer
在 vapor 依赖项中,如果你想创建自定义标签,这是要遵守的协议(protocol):
希望对你有帮助
关于html - Swift Vapor Leaf 在变量中传递 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44524372/
在我的 Package.swift 文件中尝试更新版本后,我的 Vapor 和 Vapor-MySQL 设置失败了。 最终,我想要一个包含以下内容的 Package.swift: .Package(u
在 Vapor 3 中,我能够获取到数据库的 newConnection 并使用以下命令调用原始 sql 查询: return request.withNewConnection(to: .mysql
我有一个静态网页存储在我的 Vapor 服务器的公共(public)文件夹中。它有一个index.html 文件。但是,当我导航到 root (http://localhost:8080) 时,它显示
我有一个静态网页存储在我的 Vapor 服务器的公共(public)文件夹中。它有一个index.html 文件。但是,当我导航到 root (http://localhost:8080) 时,它显示
我关注了 Vapor tutorial创建一个你好应用程序。在 Xcode 中,当我在我的 Mac 上运行运行方案时,应用程序启动并运行,正如我通过打开 http://localhost:8080/看
我正在尝试使用存储库模式将一些代码从 Vapor 3 迁移到 Vapor 4。我已经完成了 documentation of this specific pattern来自 Vapor 4 文档,我想
我可以使用计时器吗,例如 NSTimer在 Vapor(服务器端 Swift)中? 我希望我用 Vapor 编写的服务器可以偶尔主动完成一些任务。例如,每 15 分钟从网络上轮询一些数据。 如何使用
我添加了 .package(url: "https://github.com/vapor-community/postgresql-provider.git", .upToNextMajor(from
我正在使用 Vapor 开发一个简单的 Web API。为了提供更多背景信息,我是后端开发的新手。 API 的使用者将是一个 iOS 应用程序。目前,我不需要用户注册即可使用该应用程序。我想保持这种状
在我的旧 Vapor 3 代码中,我正在创建这样的模型: address.create(on: conn).flatMap { savedAddress in // do something
我从 Vapor 3 更新到 4,从 Xcode 11 更新到 12。现在 Leaf 找不到我的 *.leaf 模板。我收到“noTemplateFile”错误。 最佳答案 我在这里找到了答案:htt
我有一个使用 get 处理程序的 Controller 返回 Future .我想在响应中添加一个 header (具体来说是 Cache-Control)。我在想这应该很容易,但我没有找到如何去做。
我想用最新的 vapor 3.x 构建 vapor 工具箱。 但是,vapor toolbox 的 Package.swift 仍然有 Vapor 2.x 依赖。 .Package(url: "htt
安装 Vapor 后,我遇到以下错误 dyld:未加载库:/usr/local/opt/openssl/lib/libssl.1.0.0.dylib 引用自:/usr/local/bin/vapor
当我尝试运行实现 block 读取和队列的导入时,我从 vapor 队列收到以下错误; ErrorException: touch(): Unable to create file /tmp/stor
我正在使用 Vapor 尝试从另一台服务器获取 XML 文件,问题是我不知道如何将响应正文转换为快速字符串。 let bikesResponse = try drop.client.get("http
我想创建一个命令,您可以在其中创建用户(如数据库种子)。 但是,我无法在命令中访问数据库,我的代码如下: import Command import Crypto struct CreateUserC
他们是否可以替代 Vapor 的 session 中间件包? 我们的客户端平台不支持 cookie。 Vapor 使用 cookie 进行 session 管理。 Redis 有一个 session
对于我的 Vapor 项目,我想主要使用一个 Postgres 数据库。但是,对于某些长时间运行的请求,我想使用同一数据库的单独只读克隆。 这方面的文档非常少。如何在现有默认数据库旁边添加另一个数据库
如何在登录方法中通过电子邮件在 vapor 中正确找到用户并返回该用户或返回错误,我试过: func login(_ req: Request) throws -> Future {
我是一名优秀的程序员,十分优秀!