Conditional Rendering Of An Element

Why does this not work for me? It should render unless the page is /contact.

{{ if (ne .Page.Permalink "/contact/") }}
  <a  class="button bg-gray-300 px-3 py-1 rounded-full flex-none" href="/contact" >Contact</a>
{{ end }}

Sorry for a dumb question, I do find the docs less than helpful but I am here to try something other than liquid.

David

Use .RelPermalink. Also, the warnf function is a huge help when debugging these kinds of issues.

Have it working with this:

{{ if not (eq .URL "/contact") }}
  <a  class="button bg-gray-300 px-3 py-1 rounded-full flex-none" href="/contact" >Contact</a>
{{ end }}

Now I have a problem with this:

{{ if not (eq .URL "/tags/guide") }}
  <a  class="button bg-gray-300 px-3 py-1 rounded-full flex-none" href="/tags/guide/" >Guide</a>
{{ end }}

I am not understanding something here.

What is .URL resulting to? Also, can you link the source to your website?

Its ok, sorted, needed the trailing /, like this “/tags/guide/”.

David

Instead of the above construct use something like:
{{ if not (in .RelPermalink "/tags/guide") }}

This way you do not have to worry about missing forward slashes, because the condition now checks whether the Page Permalink value contains the specified string and not whether it is identical to your condition.

Also do not use .Page.URL as it is deprecated and at some point perhaps it will be removed.
Always use .RelPermalink or .Permalink in your templates so that they are future proofed.