Inserting a variable argument into a Silverstripe template's function?
-
26-10-2019 - |
Question
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.
Solution
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 %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow