[英]handlebars registerHelper linking to HTML file
I came across this piece of Javascript code which uses Handlebars.js and I would like to link this to my index.html page. 我遇到了这段使用Handlebars.js的Javascript代码,我想将其链接到我的index.html页面。 Can anyone help with that?
有人可以帮忙吗?
Thanks! 谢谢!
This is the original code: 这是原始代码:
//replace URL by html link
Handlebars.registerHelper('link', function(text) {
var exp = /((https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig
var exp2 = /(@[A-Za-z0-9]+)/ig
return new Handlebars.SafeString(text.replace(exp,'<a href="$1">$1</a>').replace())
})
Initially you need to include the handlerbars.js file in your HTML. 最初,您需要在HTML中包含handlerbars.js文件。
<script src="~/Scripts/handlebars-v2.0.0.js"></script>
Then 然后
If you want to return the register Helper function named "link" inside a div then you can use it like this. 如果要在div中返回名为“ link”的注册帮助器函数,则可以像这样使用它。
<div id="sample">{{link}}</div>
The output will be 输出将是
<div id="sample"><a href="$1">$1</a></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.