StormByte
Cannot invoke special form alias inside HEEX template
While trying the HEEX template engine for Phoenix I ended up receiving a very strange error that was not having previously with EEX or LEEX, and is that I can not use alias for modules inside them, like this example:
<%
alias Some.Module.XXXX
some_var = XXXX.some_func()
%>
#Rest of the HTML
The error is: (ArgumentError) cannot invoke special form alias/1 inside HEEx templates
Why is not possible to use aliases inside HEEx templates? Is this a bug or is intentional?
I know aliases are not a must but saves a lot of writing into the code.
Thanks!
Most Liked
benwilson512
Not sure about the direct rationale for the error, but I believe if you simply do the alias inside of the module or function that the heex template is a part of it should still work.
sodapopcan
Just to be that guy: I would encourage you not to set variables in your templates, there’s truly never a need for it. You can instead define helper functions in your View or LiveView and call them from your template.
StormByte
Thanks for the replies!
Sure! It is not a blockstopper since as you point it can be done inside the view as a helper. I just got confused about why this is now an error while previously was allowed and if it is intentional or not, since many times, this kind of code snippets are done for quick tests, etc.
sodapopcan
Ah, cool cool! I don’t mean to be annoying, I just point these things in out in case those less experienced were to see it as good practice.








