If you take a look at the form component generated by mix phx.gen.live, it sets a @page_title assign instead of handling the conditional logic in the heex template.
If you want to keep it in the template, here are some other options:
# `if/2` with a one liner keyword list, balances clarity and conciseness, my pick of the bunch
<h1>{if @category_id, do: gettext("Edit Category"), else: gettext("New Category")}</h1>
# pseudo-ternary, very concise but arguably too clever, also unexpected gotcha if middle bit is false-y when conditional is truth-y
<h1>{@category_id && gettext("Edit Category") || gettext("New Category")}</h1>
# not my personal preference, but for the sake of completeness
<h1 :if={@category_id}>{gettext("Edit Category")}</h1>
<h1 :if={@category_id == nil}>{gettext("New Category")}</h1> # or
<h1 :if={is_nil(@category_id)}>{gettext("New Category")}</h1> # or
<h1 :if={!@category_id}>{gettext("New Category")}</h1>
the code should you quoted should work. At least i dropped it in a heex template and it worked right away. The error message implies that you are missing a name attribute on your form or input.
If you canât figure out the issue, could you give us the full code of the form youâre trying to implement?
The difference would be that the new syntax with the inline if works only if you want to interpolate a value. The block syntax has the added benefit, that you can write additional HTML like this for example.
<%= if @category_id do %>
<span class="text-blue-400">{gettext("Edit Category")}</span>
<% else %>
<span class="text-red-600">{gettext("New Category")}<span>
<% end %>