tags:

views:

14

answers:

1

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

A: 

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"></@>
Andy Pryor
Andy, thanks for quick reply, but this is not helping. I wrote it not as macro, but as a Java class. IN any case, I could do underscore, which works, but this is not what I need. I need a dash: "-"
ipolevoy