Compare current URL with .Site.BaseURL

Good morning everyone,
I’ll try first to describe what I’m trying to achieve:

right now I have a list on my main page that shows all pages in my website except the one named “About me”.
This is achieved with the following code and works great:

{{- range.Pages }}
{{ if ne .Name "About me" }}
<li>
        {{- if .Param "datesinlist" }}<time datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">{{ .Date.Format "2006 Jan 02" }}</time> &ndash; {{ end -}}
        <a href="{{ .RelPermalink }}">{{ .Title }}</a>
</li>
{{ end }}
{{- end }}

The only problem is that each page is tagged and there are list pages for all tags, with this code the “About me” page does not shows up in the “Personal” tag list page.

In order to have it showing up in the “Personal” tag list page but not in the homepage I tried the following:

{{ if and (ne .Name "About me") (ne .Site.BaseURL .Page.BaseUrl) }}

I know that .Page.BaseURL is wrong, I tried multiple variables but I never had it working correctly, I’m trying to say “If the current URL is not the base site URL (so the homepage, defined in hugo.toml)”.

Any clue on how to do this? Or maybe any other way to discriminate that I’m not thinking of?

Thanks everyone in advance for the help, if you need more info just ask.

What about using not .IsHome .
Should do the trick: IsHome | Hugo

[EDIT]
It does filter correctly the list in the homepage but the page also don’t display in the “Personal” tag list page.

Could it maybe be because I’m in hugo preview mode?

Ah. Got it

So you have a context Problem:

within the range loop the dot refers to the page currently processed and so .IsHome inside will check the currently processed page and not the page you are on - which obviously will never be true for the “About me” page.

{{- range.Pages }}
{{ if not(and $.IsHome (eq .Name "About me")) }}

more about Context: Introduction to templating | Hugo

If you have more special stuff on your homepage, you might want to separate the templates: Base templates and blocks | Hugo

1 Like

It was the $, thank you!

If you have more special stuff on your homepage, you might want to separate the templates: Base templates and blocks | Hugo

Yeah, I just shared the small portion of the code that I needed, I’m actually modifying a real template, the Lugo one to be precise.

Marking this as solved, thank you also for the quick response! [EDIT: typo]

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.