How to get the current alias url in alias.html

If i have a custom alias.html how can I can I get the url of the alias currently being built.

If I try to access “{{ .Permalink }}”. or “{{ .RelPermalink }}” in alias.html it returns the url of the page the alias belongs to instead of the current alias url.

here is the sample code.

<!DOCTYPE html>
<html{{ with site.LanguageCode | default site.Language.Lang }} lang="{{ . }}"{{ end }}>
<head>
  <title>{{ .Permalink }}</title>
  <link rel="canonical" href="{{ .Permalink }}">
  <meta name="robots" content="noindex">
  <meta charset="utf-8">
  <script>
    
    {{- /* Perform path manipulations at build time using Hugo variables */ -}}
    {{- $currentPath := .RelPermalink -}}

Current path does not return the url of the alias being built instead it return the url the alias belongs to

You cannot.

The alias template receives the following context:

  • .Permalink
  • .Page

https://gohugo.io/content-management/urls/#customize