tadasajon
How can I easily comment out lines in a *.html.heex file?
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.
Marked As Solved
tadasajon
Here is the solution I came up with:
- create a new file in the
lib/myapp_webdirectory and define a new module in it:
defmodule HeexIgnore do
use Phoenix.Component
def ignore(assigns), do: ~H""
end
- In
lib/myapp_web.exfind the private functiondefp 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.
Thanks to @chrismccord for giving me some tips in the GitHub issue referenced by @kokolegorille
Also Liked
werkzeugh
for the record:
this is solved with <%!-- --%> since elixir v1.14.0 09/2022:
<%!-- comment
over
multiple lines --%>
https://github.com/elixir-lang/elixir/pull/11505
getting it to work in vscode:
vscode-elixir-ls supports it since 0.12.0:
https://github.com/elixir-lsp/vscode-elixir-ls/commit/9afc4d21eb7ed870f296e3d2fd34ef95cd4d16ea
i just had to add this to my settings.json to use it in vscode with the default comment-shortcut:
"custom-language-properties": {
"phoenix-heex.comments.blockComment": ["<%!--", "--%>"]
},
(phoenix-heex. might be named html-eex. or similar in your setup)
APB9785
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 <%
APB9785
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









