Joe
Joe

Reputation: 13

Inserting a variable argument into a Silverstripe template's function?

I'm using a pagination example from balbus design. In the .ss template, there is a line of code:

<% control ProductList.PaginationSummary(5) %>

Is that possible to use a variable instead of hard-coding the value 5? For example:

<% control ProductList.PaginationSummary(PSSize) %>

The variable PSSize is defined in the model and will return the number set in the CMS.

Upvotes: 0

Views: 1509

Answers (1)

Mateusz Uzdowski
Mateusz Uzdowski

Reputation: 81

The SS 2.4 templating language is very limited in terms of what it can do.

In this specific case, you could try working it out in the controller - try adjusting the $resultSet within ProductListPage_Controller::ProductList to preprocess the pagination summary to desired context size, so you can access it later from the template.

Try something like that:

$resultSet->AdjustedPaginationSummary = $resultSet->PaginationSummary($this->productsPerPage);
return $resultSet;

And then in the template you should be able to do:

<% control ProductList.AdjustedPaginationSummary %>

Upvotes: 3

Related Questions