英文:
Google App Engine Go SDK update problems with template
问题
我刚刚将我的GAE Go SDK更新到最新版本。我在我的代码上运行了gofix,但仍然有一些错误。代码以前是这样的:
AnkietaTemp = template.New(nil)
err := AnkietaTemp.ParseFile("ankieta/ankieta.html")
但现在传递nil似乎不起作用,所以我将其替换为:
AnkietaTemp = template.New("")
_, err := AnkietaTemp.ParseFile("ankieta/ankieta.html")
尝试运行我的应用程序,但在HTML源代码中,我得到的是:
<td width="400"><img src="images/{.section One}{@}{.end}"
alt="images/{.section One}{@}{.end}" width="100%"/></td>
而不是对图像文件的整洁引用。
在更新之后,现在解析模板文件的正确方法是什么?
英文:
I`ve just updated my GAE Go SDK to the newest release. I ran the gofix
on my code, but there were still some errors. 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:
AnkietaTemp = template.New("")
_, err := AnkietaTemp.ParseFile("ankieta/ankieta.html")
Tried running my app, but in HTML source I get:
<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?
答案1
得分: 3
在新的template包中,模板标签语法发生了变化,你可以在文档中看到。例如,点号(.)用于引用“当前”项,模板标签用两个花括号表示。
编辑:哦,而且不再有.section标签了。你没有提供传递给模板的Execute()方法的结构,所以我无法提供关于如何准确解决这个问题的详细信息,但我猜你可以使用{{with}}标签,像这样{{with One}}{.}{{end}}或者{{.One}}。
英文:
In the new template package the template tag syntax changed, as you can see in the documentation. E.g. 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. 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}}.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论