简体   繁体   English

Google App Engine Go SDK的模板更新问题

[英]Google App Engine Go SDK update problems with template

I`ve just updated my GAE Go SDK to the newest release. 我刚刚将GAE Go SDK更新为最新版本。 I ran the gofix on my code, but there were still some errors. 我在代码上运行了gofix,但仍然存在一些错误。 The code used to look: 用于查看的代码:

   AnkietaTemp = template.New(nil)
   err := AnkietaTemp.ParseFile("ankieta/ankieta.html")

but now passing nil doesn't seem to work, so I replaced it into: 但是现在传递nil似乎无效,因此我将其替换为:

   AnkietaTemp = template.New("")
   _, err := AnkietaTemp.ParseFile("ankieta/ankieta.html")

Tried running my app, but in HTML source I get: 尝试运行我的应用程序,但是在HTML源代码中,我得到了:

 <td width="400"><img src="images/{.section One}{@}{.end}"
alt="images/{.section One}{@}{.end}" width="100%"/></td>

Instead of a neat reference to an image file. 而不是对图像文件的简洁引用。

What is the proper way to parse the template files now, after the update? 更新后,现在解析模板文件的正确方法是什么?

In the new template package the template tag syntax changed, as you can see in the documentation . 在新的template包中,模板标记的语法已更改,如您在文档中所见。 Eg dot ( . ) is used instead of @ for referencing the "current" item and the template tags are indicated with two curly braces instead of one. 例如,用点( . )代替@来引用“当前”项,并且用两个大括号(而不是一个)来指示模板标签。

Edit: Oh, and there's no .section tag any more. 编辑:哦,并且没有.section标记了。 You didn't provide the structure you pass to template's Execute() method so I can't provide details on how mitigate that exactly, but I guess you can use {{with}} tag like {{with One}}{.}{{end}} or maybe {{.One}} . 您没有提供传递给模板的Execute()方法的结构,因此我无法提供有关如何确切缓解该问题的详细信息,但我想您可以使用{{with}}标签,例如{{with One}}{.}{{end}}{{.One}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM