<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="358718" data-post-id="358718">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Chrichton" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Chrichton/120/34984_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Chrichton
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi <a class="mention" href="/u/codeanpeace" rel="nofollow">@codeanpeace</a></p>
<p>Unfortunately</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">&lt;h1&gt;{if @category_id, do: gettext("Edit Category"), else: gettext("New Category")}&lt;/h1&gt;
</code></pre>
<p>is an invalid code.<br>
I get a compilation error:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Compiling 1 file (.ex)

** (Phoenix.LiveView.Tokenizer.ParseError) lib/helpcenter_web/live/categories/category_form.ex:45:93: expected attribute name
    (phoenix_live_view 1.0.4) lib/phoenix_live_view/tokenizer.ex:744: Phoenix.LiveView.Tokenizer.raise_syntax_error!/3
    (phoenix_live_view 1.0.4) lib/phoenix_live_view/tag_engine.ex:300: Phoenix.LiveView.TagEngine.handle_text/3
    (eex 1.18.1) lib/eex/compiler.ex:331: EEx.Compiler.generate_buffer/4
    (phoenix_live_view 1.0.4) expanding macro: Phoenix.Component.sigil_H/2
    (helpcenter 0.1.0) lib/helpcenter_web/live/categories/category_form.ex:32: HelpcenterWeb.Categories.CategoryForm.render/1
</code></pre>
<p>Can you tell me what’s the problem?<br>
Heiko</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="358718" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-does-if-heex-attribute-work/55312/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-358718" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="358718"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #21"></div>
  </section>
</div>
    <div class="postbit" id="358722" data-post-id="358722">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="kevinschweikert" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kevinschweikert/120/26866_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  kevinschweikert
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hey <a class="mention" href="/u/chrichton" rel="nofollow">@Chrichton</a>,</p>
<p>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 <code>name</code> attribute on your form or input.<br>
If you can’t figure out the issue, could you give us the full code of the form you’re trying to implement?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="358722" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-does-if-heex-attribute-work/55312/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-358722" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="358722"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="358731" data-post-id="358731">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Chrichton" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Chrichton/120/34984_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Chrichton
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi Kevin.</p>
<p>I inserted the code again and now it works.<br>
Please don’t ask me, why it didn’t work before… <img src="https://forum.elixirforum.com/images/emoji/apple/innocent.png?v=15" title=":innocent:" class="emoji" alt=":innocent:" loading="lazy" width="20" height="20"></p>
<p>Generally I do find it irritating, that there is the old style and the new style:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">&lt;!-- old style --&gt;
&lt;%= @something %&gt;

&lt;!-- new style --&gt;
{@something}`
</code></pre>
<p>and both still do work.</p>
<p>I want to use the new style.</p>
<p>The old style for if else would be</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"> &lt;%= if @category_id do %&gt;
   {gettext("Edit Category")}
 &lt;% else %&gt;
   {gettext("New Category")}
 &lt;% end %&gt;
</code></pre>
<p>So</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">{if @category_id, do: gettext("Edit Category"), else: gettext("New Category")}
</code></pre>
<p>is just the new style using the expression</p>
<blockquote>
<p>if, do: else:</p>
</blockquote>
<p>right?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="358731" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-does-if-heex-attribute-work/55312/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-358731" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="358731"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #23"></div>
  </section>
</div>
    <div class="postbit" id="358733" data-post-id="358733">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="Chrichton" data-post="24" data-topic="55312">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/chrichton/48/34984_2.png" class="avatar"> Chrichton:</div>
<blockquote>
<p>The old style for if else would be</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"> &lt;%= if @category_id do %&gt;
   {gettext("Edit Category")}
 &lt;% else %&gt;
   {gettext("New Category")}
 &lt;% end %&gt;
</code></pre>
<p>So</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">{if @category_id, do: gettext("Edit Category"), else: gettext("New Category")}
</code></pre>
<p>is just the new style using the expression</p>
<blockquote>
<p>if, do: else:</p>
</blockquote>
<p>right?</p>
</blockquote>
</aside>
<p>While moving to single line <code>if</code> works, the “old style” is still the way to go for cases where the single line <code>if</code> doesn’t work.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="358733" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-does-if-heex-attribute-work/55312/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-358733" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="358733"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #24"></div>
  </section>
</div>
    <div class="postbit" id="358734" data-post-id="358734">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="kevinschweikert" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kevinschweikert/120/26866_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  kevinschweikert
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The difference would be that the new syntax with the inline <code>if</code> 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.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">&lt;%= if @category_id do %&gt;
   &lt;span class="text-blue-400"&gt;{gettext("Edit Category")}&lt;/span&gt;
 &lt;% else %&gt;
   &lt;span class="text-red-600"&gt;{gettext("New Category")}&lt;span&gt;
 &lt;% end %&gt;
</code></pre>
<p>This wouldn’t work when you write it like this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">{if @category_id, do: "&lt;span class=\"text-blue-400\"&gt;#{gettext("Edit Category")}&lt;/span&gt;", else: "&lt;span class=\"text-red-600\"&gt;#{gettext("New Category")}&lt;span&gt;"}
</code></pre>
<p>As you can see, you would have to write it as a string and then it wouldn’t be handled as HTML</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="358734" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-does-if-heex-attribute-work/55312/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-358734" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="358734"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>