I’m having a bit of trouble wrapping my brain around how I would pass a dynamic fragment to ~p
inside a macro:
defmacro __using__(opts) do
@path opts.path
quote do
def handle_event("event", _, socket) do
path = ~p"/#{@path}"
# ...
{:noreply, socket}
end
end
end
I’ve tried a fair number of functions from the Macro
module both inside, namely escape
and expand
/expand_once
which are the ones I though would do it as well as unquote
(and even quote
for good measure). I understand that passing an argument to the ~p
macro is going to quote
it and when it’s called already inside a quote
block, well, uh… oh boy As I have it does produce the correct route but of course gives a console warning. I feel like this question must have been answered before but I can’t find it and my brain hurts. At the very least I’m treating this forum as a rubber duck but any help would be much appreciated.