使用模板导出双引号

时间:2019-08-13 03:03:40

标签: go

我正在使用template导出go中的",但它仅返回"。有没有办法让它导出"

import (
    "html/template"
)

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

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

然后,要在文件中使用,我将{{ testf }}

1 个答案:

答案 0 :(得分:2)

这是因为let minSquareDistance = null; let closestIndex = null; self.lines.forEach((line, index) => { const squareDistance = line.squareDistanceFrom(x, y); if (index === 0 || squareDistance < minSquareDistance) { minSquareDistance = squareDistance; closestIndex = index; } }); let mainArrayIndex; let subArrayIndex; self.penciledLines.forEach((arr, mainIndex) => { arr.forEach((line, subIndex) => { const squareDistance = line.squareDistanceFrom(x, y); if (squareDistance < minSquareDistance || minSquareDistance === null) { minSquareDistance = squareDistance; // cancel closestIndex closestIndex = null; mainArrayIndex = mainIndex; subArrayIndex = subIndex; } }); }); const distanceCheck = minSquareDistance; if (distanceCheck > 10) { self.selectedLine = {}; self.selectedArrayLinesIndex = null; self.selectedArrayLinesToggle = false; } 将使其成为html安全的代码,可以转义所有html特殊字符并将其替换为html编码。

为避免这种情况,应将html/template替换为html/template

text/template