Override Internal Template?

I presume it’s possible to override Hugo’s built-in internal template[s], but I’m not quite sure where within my theme I would put my custom version, or whether I have to override the entire internal template, or can just override one particular aspect?

To be exact, I’m looking for a way to cutomise the new paginator’s template. I know I can style it up, to a degree, with CSS, but certain visual aspects are hard-wired in to the template_embedded.go file –for example the use of angle brackets << for the first/previous…next/last links:

````t.AddInternalTemplate("", “pagination.html”, `{{ pag := .Paginator }}
{{ if gt $pag.TotalPages 1 }}

    {{ with $pag.First }}
  • ««
  • {{ end }}````

    I’d like to replace those >> with something else:

Copy and paste it into your own template.

Theres no magic bullet in there.

1 Like

Nice one. Ta!

Just to expand on [bjornerik][1]'s answer [and possibly for my own future reference!]:

I added a “pagination.html” file to my themes layouts > partials directory, containing the meat and potatoes of the approriate function from [template_embedded.go][2]:


{{ $pag := $.Paginator }}
{{ if gt $pag.TotalPages 1 }}
<ul class="pagination">
{{ with $pag.First }}
<li>
<a href="{{ .Url }}" aria-label="First"><span aria-hidden="true">&laquo;&laquo;</span></a>
</li>
{{ end }}
<li
{{ if not $pag.HasPrev }}class="disabled"{{ end }}>
<a href="{{ if $pag.HasPrev }}{{ $pag.Prev.Url }}{{ end }}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a>
</li>
{{ range $pag.Pagers }}
<li
{{ if eq . $pag }}class="active"{{ end }}><a href="{{ .Url }}">{{ .PageNumber }}</a></li>
{{ end }}
<li
{{ if not $pag.HasNext }}class="disabled"{{ end }}>
<a href="{{ if $pag.HasNext }}{{ $pag.Next.Url }}{{ end }}" aria-label="Next"><span aria-hidden="true">&raquo;</span></a>
</li>
{{ with $pag.Last }}
<li>
<a href="{{ .Url }}" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a>
</li>
{{ end }}
</ul>
{{ end }}
{{"<!-- end pagination partial //-->" | safeHtml}}````
----

and then changed the code in my template's *index.html* from referencing the internal template: `{{ template "_internal/pagination.html" . }}` to reference the new partial instead: `{{ template "theme/partials/pagination.html" . }}`.

Job's a good 'un! Now to start customising....

  [1]: http://discuss.gohugo.io/users/bjornerik
  [2]: https://github.com/spf13/hugo/blob/master/tpl/template_embedded.go
1 Like

I’m having trouble here. I’ve tried your example, which is presumably from before the partial helper was introduced.

{{ template "partials/pagination.html" . }} Which gives the error:

template: partials/pagination.html:6:20 executing "partials/pagination.html" at <.URL>: URL is not a field of struct type *hugo.pager

I’ve also tried using {{ partial "pagination.html" . }} which yeilds:

executing "partials/pagination.html at <.URL>: URL is not a field of struct type *hugolib.pager in partials/pagination.html

If instead I use the internal pagination template: {{ template "_internal/pagination.html" . }} everything works properly.

I copied the internal template from master and modified only where the disabled class was added.

This is a Hugo version mismatch issue …

  • Your partial/pagination.html is 0.14-DEV with .URL
  • .Url and some others are deprecated in 0.14 in favor of .URL. In 0.14-DEV both will work. In 0.13 only the first, if that makes sense.

So you will either have to fix pagination.html (URL => Url) or run with 0.14-DEV.

My mistake! Everything is working well, now.

Thanks