Compare .Site.BaseURL with a string

If you want to compare .Site.BaseURL with a string, convert it to string first:

{{ $baseurl := printf "%s" .Site.BaseURL }}
{{ if eq $baseurl .Site.Params.lasturl }}
{{ end }}

Since its type is “template.URL”, not string. You can check it by {{ printf "%T" $.Site.BaseURL }}

I use different url’s for my development and production sites. And set the base url via command line (using make).


Thanks this was helpful in setting my RSS feed title in rss.xml:

             If the page's .Title exists AND if it is not the same as the site's title,
             set the title to

             "Subsection title" on "My site title"

             else, just

             "My site title"

        <title>{{ with .Title }}{{ $title := printf "%s" $.Title }}{{ if not (eq $title $.Site.Title)}}{{$title}} on {{ end }}{{ end }}{{ .Site.Title }}</title>
1 Like