Getting url of element in .Site.Pages [SOLVED]

I’m ranging over the 10 latest blog posts via .Site.Pages. This partial is rendered at the and of a blog post. It can happen that the current blog post is one of the latest 10. Therefore I would like to ignore this blog post. My problem is that I can’t get the url of the current element/page in .Site.Pages.

The current state of my code (which excludes the about page):

<ul id="post-list" class="archive readmore">
    {{ 	range first 10 .Site.Pages }}
        # Get relative page url like about/ 
    	{{ $url := replace .Permalink (printf "%s" .Site.BaseURL) "" }}

        {{ if ne $url "about/" }}
        # Do Something
        {{ end }}
   {{ end }}

The condition might look like {{ if and (ne $url "about/") (ne $url RelativeURLToCurrentPage) }}

If that’s happening on a page (which it looks like it is), you should be able use something like

{{ if ne .UniqueID $.UniqueID }}
{{ end }}

(If you’re curious, the $ is the starting value of .)

(It doesn’t look like UniqueID is mentioned anywhere in the docs… perhaps we should look into making those auto-generated.)

1 Like

Thanks for the tip. That worked great.

Alternatively you could compare a variable that both documents share in their frontmatter, for example the title.

{{ if and (ne $url "about/") (ne $.Title .Title) }

The possibility that two posts share the same title is very low.