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)
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.