开发者

FreeMarker cannot seem to parse HTML 5 data-* atttributes, chokes on dash

I wrote a simple custom directive, and have it pass all attributes through as regular element attributes. The syntax of the tag as follows:

<@link_to controller="unobtrusive" action="do-get" data-target="result">Do Get

Unfortunately, I get an exception:

Caused by: freemarker.core.ParseException: Encountered "-" at line 32, column 56 in unobtrusive/index.ftl. Was expecting: "=" ...

This is because it cannot seem to parse data-target attribute. When I change it to "data_target" with the underscore, all is fine.... but I really would need the dash: "-".

Can someone help?

开发者_如何转开发

Thanks, Igor


Try this tip from the FAQ

<@link_to controller="unobtrusive" action="do-get" "data-target"="result">

I haven't tried this personally so can't vouch if it will work.


I just stuck in the same problem. <@form.textarea ... data-maxCount="100" />. It seems that freemarker misinterprets special characters in names... Freemarker FAQ


As of 2.3.22, you can use - (and . and :) as part of any name if you precede it with a \, like in <@link_to data\-target=...>. (It's not too cute, but - is already used as subtraction operator, and fixing this wouldn't backward compatible, and so must wait for a major FTL version increase.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜