douzhi9478 2019-08-13 03:03
浏览 8
已采纳

使用模板导出双引号

I'm using template to export " in go but it returns only ". Is there a way to get it to export " instead.

import (
    "html/template"
)

//Testf  a test function
func Testf() string {
    return "\""
}

//MapToFunctions Map actions to functions
var MapToFunctions = template.FuncMap{
    "testf":      Testf}

Then, to use in a file, I'd put {{ testf }}

  • 写回答

1条回答 默认 最新

  • dongrui6787 2019-08-13 15:36
    关注

    That is because html/template will make it html safe which escapes all the html special characters and replacing them with html encoding.

    In order to avoid that, you should replace html/template with text/template

    text/template

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?