[Closed] BaseURL not showing in pagination

I ran into trouble when using the theme ‘Casper’ from @vjeantet with the pagination tool. As it’s not necessarily a bug, I thought about posting it here first (before opening an issue on GH).

Here is the case. My baseURL is a subfolder : http://example.com/blog/

The pagination {{ .Next.URL }} shows up as http://example.com/page/2 instead of the expected : http://example.com/blog/page/2

I tried to insert {{.Site.BaseURL}} before .Next.URL but I get the following error :

ERROR: 2015/06/21 template: theme/partials/pagination.html:7:42: executing "theme/partials/pagination.html" at <.Site.BaseURL>: Site is not a field of struct type *hugolib.Pager in theme/partials/pagination.html

I guess I am missing something here. If not, can we think of using the baseURL when the pagination is generated ?

First, I’m pretty sure you are wrong when stating that the Next.URL is http://example.com/page/2. The Paginator URL is relative to the context root (=> blog).

Second: BaseURL isn’t a property of Pager, so you probably want to say:

{{ $.Site.BaseURL }}

BTW; I recently added some utility funcs named absURL and relURL. Both of them take BaseURL into account, so you can do

{{ .Next.URL | absURL }}

These are only available in Hugo DEV (0.15) if memory serves me correctly.

Thanks for your answer @bep. I am probably wrong, but this is the behavior I’m observing.
My version is 0.14 windows build by the way.

I didn’t know the {{ $.Site.BaseURL }} syntax. What does the “$” stands for ? Is it the same as variable definition in template ?
I couldn’t get how to make it work properly.

Here is the code that generates the pagination in Casper :

<main id="content" class="content" role="main">
    {{ $paginator := .Paginate (where .Data.Pages "Section" "post") }}
    <div class="extra-pagination inner">
        {{ partial "pagination.html" $paginator }}
    </div>
    {{ range $index, $page := $paginator.Pages }}
        {{ .Render "li" }}
    {{ end }}
    {{ partial "pagination.html" $paginator }}

</main>

And here is pagination.html :

<nav class="pagination" role="navigation">
    {{if .HasPrev}}
        <a class="newer-posts" href="{{ .Prev.URL }}">&larr; Newer Posts</a>
    {{end}}
    <span class="page-number">Page {{ .PageNumber }} of {{.TotalPages}}</span>
    {{if .HasNext}}
        <a class="older-posts" href="{{ .Next.URL }}">Older Posts &rarr;</a>
    {{end}}
</nav>

Sorry if I misunderstand few things in here.

I’ll try to use the last dev later on.

$ stands for “the outer most dot context”, in this case the Node – which contains the Site etc.

What is your absurlify setting?

Thanks for the explaination about $.

I could not understand what you meant by the absurify setting ? Don’t remember having seen that in the doc before (I’m not a power user if that’s not yet clear ;-D ).

Well, my memory was wrong anyhow. I meant canonifyurls.

You can see the value doing hugo config.

Amazing @bep,

Callling hugo config told me that canonifyurls = false .

I only had to add canonifyurls = true to my config file to fix it.

Thanks for the time spent on that Bep.

I had the same problem (with Hugo 0.18) but what fixed it was the opposite:
I had to disable canonifyurls which was set to true in my config file.