views:

159

answers:

2

Does anybody know how to get a velocity macro to run when it's prepended by an Octothorpe?

I have a velocity macro called #macro(getUniqueID $id)

And I want to use it to spit out an id to be used by jQuery.find() which uses CSS selectors which means that the id needs to be prepended by another octothorpe.

jquery.find("##getUniqueID('id')")
dosn't work

nor does

#set($id = #getUniqueID('id')) jquery.find(#$id)

nor does

#set($id = '#getUniqueID("id")') jquery.find(#$id)

nor

#set($id = "#getUniqueID('id')") jquery.find(#$id)

A: 

From my experiments the following escaping should work for you:

<h2 id="#octothorpe">foo</h2>

$('#\\#octothorpe');
> [h2##octothorpe]
DEfusion
A: 

If you're trying to find a div by the id, you would need to do jQuery.find('#'+id) vs #id. Nevertheless, you can probably use the \ to escape your second hash symbol.

wambotron