From elixir-phoenix
Phoenix HEEx template rules covering interpolation syntax, form building, class lists, conditional rendering, comments, and common anti-patterns. Use when writing or reviewing HEEx templates.
How this skill is triggered — by the user, by Claude, or both
Slash command
/elixir-phoenix:heex-templatesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- Phoenix templates **always** use `~H` or .html.heex files (known as HEEx), **never** use `~E`
~H or .html.heex files (known as HEEx), never use ~EPhoenix.Component.form/1 and Phoenix.Component.inputs_for/1 function to build forms. Never use Phoenix.HTML.form_for or Phoenix.HTML.inputs_for as they are outdatedPhoenix.Component.to_form/2:assign(socket, form: to_form(...))
<.form for={@form} id="msg-form">
<.input field={@form[:content]} type="text" />
</.form>
your_app_web.ex's html_helpers block, so they will be available to all LiveViews, LiveComponents, and all modules that do use YourAppWeb, :htmlif/else but does NOT support if/else if or if/elsif. **Never use else if or elseif in Elixir**, **always** use condorcase` for multiple conditionals:<%!-- NEVER do this (invalid) --%>
<%= if condition do %>
...
<% else if other_condition %>
...
<% end %>
<%!-- ALWAYS do this --%>
<%= cond do %>
<% condition -> %>
...
<% condition2 -> %>
...
<% true -> %>
...
<% end %>
HEEx require special tag annotation if you want to insert literal curly braces. For code snippets in <pre> or <code> blocks, annotate the parent tag with phx-no-curly-interpolation:
<code phx-no-curly-interpolation>
let obj = {key: "val"}
</code>
Within annotated tags, you can use { and } without escaping, and dynamic Elixir expressions can still be used with <%= ... %> syntax.
HEEx class attrs support lists, but you must always use list [...] syntax. Use the class list syntax to conditionally add classes:
<a class={[
"px-2 text-white",
@some_flag && "py-5",
if(@other_condition, do: "border-red-500", else: "border-blue-100"),
]}>Text</a>
Always wrap if's inside {...} expressions with parens.
Never do this (missing [ and ]):
<%!-- INVALID --%>
<a class={
"px-2 text-white",
@some_flag && "py-5"
}> ...
<% Enum.each %> or non-for comprehensions for generating template content, instead always use <%= for item <- @collection do %><%!-- comment --%>. Always use this syntax for template commentsHEEx allows interpolation via {...} and <%= ... %>, but the <%= %> only works within tag bodies.
Always do this:
<div id={@id}>
{@my_assign}
<%= if @some_block_condition do %>
{@another_assign}
<% end %>
</div>
Never do this (syntax error):
<%!-- THIS IS INVALID --%>
<div id="<%= @invalid_interpolation %>">
{if @invalid_block_construct do}
{end}
</div>
Rules:
{...} for interpolation within tag attributes{...} for interpolation of values within tag bodies<%= ... %> for block constructs (if, cond, case, for) within tag bodiesnpx claudepluginhub code0100fun/botfiles --plugin elixir-phoenixRender Phoenix views and HEEx templates using embed_templates, assigns, interpolation, conditionals (if/unless/case), for loops, function components, and slots. Useful for dynamic HTML in Phoenix apps.
Enforces Elixir best practices like pattern matching over if/else, pipe operator for chaining, with for sequential fallible ops, @impl true, and let-it-crash when editing .ex/.exs files.
Provides Phoenix LiveView best practices: no DB queries in mount (called twice), load data in handle_params, security scopes, scoped PubSub topics, GenServer polling, async assigns, and gotchas.