2010-10-14 34 views
0

我寫了一個簡單的自定義指令,並讓它傳遞所有屬性作爲常規元素屬性。標籤的語法如下:FreeMarker似乎無法解析HTML 5數據* * atttributes

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

不幸的是,我得到一個異常:

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

這是因爲它似乎無法解析「數據目標」屬性。當我用下劃線將它改爲「data_target」時,一切都很好......但我真的需要短劃線:「 - 」。

有人可以幫忙嗎?

感謝,

伊戈爾

回答

1

你的問題是 - 但在這種情況下它沒有被用來作爲一個HTML標籤,它是一個自定義指令的FTL參數。 FTL顯然不喜歡變量名中的破折號,但這並不妨礙你將破折號包含在輸出中。

你沒有包含你的指令,但我認爲你想要完成的可能是這樣的。只需在宏中編寫鏈接,將data_target引用爲$ {data_target}。注意結果有數據目標作爲輸出。

<#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

Andy,感謝您的快速回復,但這不是幫助。我寫它不是宏,而是Java類。無論如何,我可以做下劃線,這是可行的,但這不是我所需要的。我需要一個破折號:「 - 」 – ipolevoy 2010-10-27 15:01:29

+0

Freemarker是模板語言,並且對HTML一無所知。是的freemarker經常被用來生成html,但它不解析它,它肯定不會因爲某些html功能而被絆倒。 – Andy 2010-11-09 00:53:00

2

截至2.3.22,你可以,如果你有一個\它的前面,就像在<@link_to data\-target=...>使用-(和.:)任何名稱的一部分。 (它不是太可愛,但-已經被用作減法運算符,並且修復它不會向後兼容,所以必須等待主要的FTL版本增加。)

+0

感謝您修復它。似乎工作。但IntelliJ 14.1.2將此標記爲錯誤。有沒有機會在IntelliJ中修復這個語法? – ipolevoy 2015-06-09 02:30:57

+0

你應該向任何維護該插件的人報告(JetBrains,我猜)。作爲暫時的解決方法,他們可能會調用Freemarker來檢查模板語法,在這種情況下,您可以手動替換該插件使用的'freemarker.jar'。 – ddekany 2015-06-09 06:37:20