How to pass PaginatePath to template?

In config.toml I have set PaginatePath = "pg". Now I want to pass this config to a Js variable. I tried different ways but I couldn’t get the PaginatePath:

  • .Site.PaginatePath
  • .Site.paginatePath
  • .Paginator.Path
  • .Paginator.path

Non of them above works. I can only get it from a full relative url:

  • .Paginator.Next.URL (or .Prev) and use Js to get the pg str.

But the solution above is not safe. I hope there is a trick or official way to get PaginatePath. Thanks in advance.

Update 05:32 / 14 Feb 2019

The used case for PaginatePath is I wanna pass it to a Js function of mine so it will generate links and redirect visitors to it. Below is a sample of my code (enough to summarize the case):

<-- HTML + Go template -->
<input id="pgNum" min="1" step="1" max="{{.Paginator.TotalPages}}"/>
<script>
	document.querySelector("#pgNum").onchange = () => nav({{.Site.PaginatePath}});
</script>

My nav(pathPg) require to know a the path so it could generate the link. In the fixed code, I could normally remove the parameter and set a ‘page’ as const. But I want to make a flexible theme so a const is not my cup of tea.

[about my nav]
This nav will allow visitors easily jump to any pos with a numeric keyboard. (I don’t like select tag, scrolling is a bad UX)

That value isn’t available in the templates.

How come?
Many values in config.toml are available in the template, why this one couldn’t?

How come?

Well, you’re the first one to ask for it AFAIK. Can you give a fuller use case? What’s the rationale? What are you trying to accomplish?

I’ve updated my topic.

Can you use the .Paginator.Pagers to output a JS array of pager URLs? OnChange could redirect to the indexed URL.

1 Like

Thanks for suggestion, you idea should work well with a list of nav. However, mine is input like this:

Which is still involve Js client to separate the URL to get custom pager-path. I guess I have to do it in my own way. Thank you anyway, hope you guy could consider to add that var in the future Hugo version.

Very few of the config values are available in the templates. The config tells Hugo how to construct URLs etc. If people started to use that same config to construct URLs based on how it currently works, we would have no way future way to change how those URLs were constructed without breaking stuff and make people angry.

Hey, I’ve just found a new solution that is to create a new params’ option with the same value of PaginatePath then I use it. Problem solved. So yeah, I agree with you that we don’t need to change anything now.

Just to make myself clear: I’m all for solving real problems – but the obvious simple short term option isnt’t always the cheapest in the long term.

1 Like

By cheap you mean?

Expensive = lots of work

1 Like