doufan1363 2019-07-05 10:51
浏览 164
已采纳

如何停止转义html / template的路径(尝试使用.HTML .JS等)

I am using the html/template functionality to assemble a page and on of the variables I'm supplying to the template is URI in the form "/some/path/etc" which is used as a parameter to a JS function called in a onClick="..".

No matter what, the string used in this configuration will be escaped with backslashes : "\/some\/path\/etc"

As you can see in the playground example below, I tried all the .HTML(), .JS() etc. functions but nothing seems to stop the escaping.

See Go Playground example here: https://play.golang.org/p/2gdghTpQHKP

How can I get this URI "as is" into the template result?

  • 写回答

1条回答 默认 最新

  • dtny30176 2019-07-08 12:28
    关注

    Thanks to mkopriva for his comment.

    As far as I could see there is no way (as mkopriva mentioned) to handling a HRML attribute value fragment in a Go HTML template. So the options are:

    1. Leave it as is (it seems that at least in my use case the URI even works in the further processing with the escaped forward slashes)
    2. first concatenate the complete attribute, so that the "HTML Attribute" way will accept it
    3. Write a construction function that takes parts and assembles the final attribute value inside the template execution
    4. Hardcode the value in some form
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统