开发者

FreeMarker cannot seem to parse HTML 5 data-* atttributes

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 unders开发者_如何转开发core, all is fine.... but I really would need the dash: "-".

Can someone help?

Thanks,

Igor


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.)


Your problem is the - but in that context it's not being used as an HTML tag, it's an FTL argument for a custom directive. FTL doesn't like dashes in variable names apparently, but that won't prevent you from including the dash in the output.

You didn't include your directive, but I think what your trying to accomplish might look like this. Just write your link in the macro, referencing the data_target as ${data_target}. Notice the result has data-target as output.

<#macro link_to controller action data_target>
     Here is the controller: ${controller}  
     Here is the action: ${action}
     Here is the data-target: ${data_target}
</#macro> 

<@link_to controller="unobtrusive" action="do-get" data_target="result"></@>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜