草庐IT

Html-Templates

全部标签

json - 从 json post 请求中转义 html

我想将请求中的一些json转换为html,但它不起作用,解码json时出现错误import("html/template""encoding/json""net/http""io""io/ioutil""log")funcanyFunction(whttp.ResponseWriter,r*http.Request){body,err:=ioutil.ReadAll(r.Body)iferr!=nil{log.Print(err)}ri,wo:=io.Pipe()gotemplate.HTMLEscape(wo,body)vart[]customStructjson.NewDecode

templates - 使用数据解析多个模板

如何将数据传递到正确的模板?我有以下模板并想解析它们layout.html:......{{template"main"}}list.html:{{define"main"}}{{range$index,$element:=.}}{{$element.Data1}}{{$element.Data2}}{{$element.Data3}}{{end}}{{end}}当我在处理函数中使用它时,只执行“主”模板,我没有得到布局。t,err:=template.ParseFiles(layoutPath,templatePath)t.ExecuteTemplate(w,"main",Data)

json - 如何以 Sendgrid API 接受的格式将 html 嵌入到 json 中?

我一直在尝试使用SendgridAPI发送HTML电子邮件,但未能成功将html嵌入到json请求中。这是我尝试发送的html示例(emailtpl):我尝试过的事情:html.EscapeString(emailtpl)strconv.Quote(emailtpl)在json模板中使用反引号`将json模板中的值用单引号括起来。base64.StdEncoding.EncodeToString([]byte(emailtpl))仅显示base64乱码。项目#1和#5是Sendgrid接受的唯一解决方案,但发送的html不正确(如屏幕截图所示)。项目#2-#4都会导致状态400错误请求

html - Buffalo v0.11.0 与 flash 和 application.html 有问题吗?

我是Golang和Buffalo的初学者。我正在尝试使用https://github.com/gobuffalo/authrecipe中的authrecipe创建密码身份验证服务.但是,在尝试使用buffalodev运行它时,我从JSON转储中收到以下错误:ERRO[2018-05-10T14:20:48-04:00]application.html:line14:_flash.html:第3行:flash:未知标识符content_type=text/htmldb="0s"duration="5.354757ms"human_size="0B"method=GETparams="{}

html - 使用 Golang 将已解析的 html 字符串从数据库显示到模板

给定我的模型typeCriteriastruct{...CriteriaIDstring`db:"criteria_id"`CriteriaNamestring`db:"criteria_name"`...和ControllerfuncCriteriaReadGET(whttp.ResponseWriter,r*http.Request){.....//Displaytheviewv:=view.New(r)v.Name="criteria/read"v.Vars["criteria"]=resultv.Render(w)}结果中的一列(来self的模型的查询结果)包含html标签,这

templates - 如何使用结构或变量值的字段作为模板名称?

我们可以通过{{define"home"}}定义模板名称,然后通过{{template"home"}}将其加载到其他(父)模板中>.如何通过变量值{{template.TemplateName}}加载模板。或者这是不可能的? 最佳答案 很遗憾,你不能。{{template}}操作的语法:{{template"name"}}Thetemplatewiththespecifiednameisexecutedwithnildata.{{template"name"pipeline}}Thetemplatewiththespecifiedn

templates - 多个文件的划分模板不提供数据

我的模板有1个文件(原始文件)按预期工作,现在当它变大时我开始将它分成3个文件并且只是将原始文件中的数据复制并粘贴到3个文件中,我能够看到模板已成功执行,但start和end模板中缺少数据,只有main模板从structData正确接收数据例如startTemple.txt{{define"start"}}...{{end}}main.txt(hereiincludebothtemplate){{template"start"}}...{{template"end"}}endTemplate.txt{{define"end"}}...{{end}}我使用以下t,err:=templat

templates - 如何在 Go html/template 中获取 map 元素的结构字段?

我有一个结构任务:typeTaskstruct{cmdstringargs[]stringdescstring}然后我初始化了一个映射,它将上面的Task结构作为一个值,一个string作为键(任务名称)vartaskMap=map[string]Task{"find":Task{cmd:"find",args:[]string{"/tmp/"},desc:"findfilesin/tmpdir",},"grep":Task{cmd:"grep",args:[]string{"foo","/tmp/*","-R"},desc:"grepfilesmatchhavingfoo",},}我

html - go/golang 服务器中的静态 css 文件

我如何在go中提供静态css文件(go版本go1.9.1linux/amd64)?我目前的代码不起作用(它显示网站但看不到css)。这是我尝试使用go处理程序使用标准文件服务。当我进入页面源并单击指向css/styles.css的链接时,它似乎是可见的并且正确重定向(在正确的url下)。我想我对某些解析步骤缺乏了解。packagemainimport("html/template""net/http""fmt")const(PORT=":3000"HOST="localhost")funchandleBooks(whttp.ResponseWriter,r*http.Request){

templates - 如何从已解析的模板中获取模板 'actions' 的 map 或列表?

所以我想以某种方式将模板中定义的所有{{.blahblah}}操作作为字符串片段。例如,如果我有这个模板:{{.name}}{{.age}}我希望能够得到[]string{"name","age"}。假设模板具有方法func(t*Template)Fields()[]string:t:=template.New("cooltemplate").Parse(`{{.name}}{{.age}}`)ift.Fields()==[]string{"name","age"}{fmt.Println("Yay,nowIknowwhatfieldsIcanpassin!")//Nowletspas