Custom function parameters

I’m using a custom function to take the total number of pages and produce an array using javascript


The array that spits out looks a bit like this:

[
	{
		"value": "«",
		"linkTo": 1
	},
	{
		"value": "‹",
		"linkTo": 1
	},
	{
		"value": "1",
		"active": true,
		"linkTo": 1
	},
	{
		"value": "2",
		"active": false,
		"linkTo": 2
	},
	{
		"value": "3",
		"active": false,
		"linkTo": 3
	},
	{
		"value": "…"
	},
	{
		"value": "16",
		"linkTo": 16
	},
	{
		"value": "›",
		"linkTo": 2
	},
	{
		"value": "»",
		"linkTo": 16
	}
]

I can pass the function the pageCount from my REST API meta section. I’d like to pass the query params to the function too. I can get them by reading the window url in javascript, but it would be cleaner to get them in the function call. Is there a way to pass more than one parameter to the function “data”?

Function “data” or you meant “pagination”

What I want to do, can’t figure out is something like this:

function('pagination', get('query').get('p'))

The pagination function is passed a data variable with one value from get(‘pageCount’). I want to pass it two variables.
Inside of the pagination function, the first line looks like this:

let pageCount = data.value;

// I want it to look more like this:
let pageCount = data.value.pageCount;
let currentPage = data.value.currentPage;

My current approach is to bake this into the top of the function, and it feels like there is a better way:

  const currentURL = window.location.href;
  const searchParams = new URLSearchParams(new URL(currentURL).search);
  const currentPage = parseInt(searchParams.get('p'), 10) || 1;

Did that make sense?

@will_lutz

Currently nesting functions is not possible, but we left the window open for the implementation in future.

What you can do for now, is use Divhunt built-in functions.

$dh.query() returns an object with all GET params (this is what you need)
$dh.site() returns object of site data like ID, name, etc
$dh.domain() returns domain data, etc
$dh.client() returns client data (Divhunt client, not your website client)
$dh.language() returns language data