Suppose I have a *.heex template file that I am iterating rapidly on and I just want to comment out a chunk of it for a few moments. What is the syntax for this? Most of the approaches I have tried just throw errors.
I have resorted to just creating a new empty file, then deleting the lines I want to comment out entirely, saving them in the new file, then copy-pasting them back in later when I want to uncomment them. This is super-laborious.
Thanks. That issue seems to be directly related to my problem. I’m still not crystal clear on how to comment out lines in a *.heex file, though – I asked for some more clarification in the issue.
Just looked at your code, the example I just gave will work until you hit your other %> — woops, thanks for the catch @APB9785.
I’m pretty sure I don’t have this issue in my heex files using the standard html comment syntax. I’ll check later and let you know why/if it works for me.
I have tried commenting-out the third list item using the syntax you suggested. I get the following error:
Compilation error in file lib/myapp_web/views/product_view.ex ==
** (Phoenix.LiveView.HTMLTokenizer.ParseError) lib/myapp_web/templates/product/show.html.heex:17:3: unmatched closing tag. Expected </ul> for <ul> at line 2, got: </li>
The problem is that there is a <%= something %> within the section that I want to enclose in the comment, so the ending tag for that something ends up closing the comment.
Yes, just quickly checked and I can second @tadasajon and @APB9785 that I receive that compilation error when <%= something %> pops up inside the comment.
Off the top of my head, is this behavior happening because when the html is being parsed/interpolated by thePhoenix heex engine, it is treating <!— —> like an html tag? Is that how html interprets the comment in general?
Then the interpolation would throw an error as it seems to be doing.
In which case, do we just need to add something to identify the comment tag syntax? Or is it something else or much more complex?
The parser identifies <!-- as a comment in handle_text, and passes it off to handle_comment, which needs to find a closing --> or it will raise. The problem is that it seems to “give up” on the search as soon as it hits a <%
create a new file in the lib/myapp_web directory and define a new module in it:
defmodule HeexIgnore do
use Phoenix.Component
def ignore(assigns), do: ~H""
end
In lib/myapp_web.ex find the private function defp view_helpers do... which contains several import statements. Add this line as one of the imports in that function:
import HeexIgnore
Now all your templates should be able to add the <.ignore> ... </.ignore> incantation in order to completely ignore large chunks of lines.
I started reading the issue around this that everyone’s been having a conversation on, and not sure I have much else to add. Seems very intentional that they have currently chose this implementation around the comments and sounds like there are some workarounds if you need a different behavior until they can revisit this again and discuss more scenarios.
Thanks for the links!
Edit: Yes, looks like @tadasajon went with one of those workarounds.