I have follwoing query string generated by a "search form"
results?pagefrom=18&pageto=30&country=2&state=&city=0&keyword=&status=all&cmd=basic_search&Submit=Start+Searching
I need to know how do i get this into the pagination generation in volt like below
<li class="previous"><a href="/search/results?page={{ page.before }} & NEEDS TO ADD ABOVE QUERY AS IT IS HERE TO WORK ">Previous</a></li>
I'm using something like this:
<li class="previous"><a href="/search/results?<?php echo http_build_query(array_merge($this->request->getQuery(), ['page' => $page->before])); ?>">Previous</a></li>
For more convenience, create marco:
{%- macro pagination_url(url, page) %}
{{ url }}?<?php echo http_build_query(array_merge($this->request->getQuery(), ['page' => $page->before])); ?>
{% endmacro %}
<li class="previous"><a href="{{ pagination_url('/search/results', page.before) }}">Previous</a></li>
Or you can add this function to volt compiler:
$compiler = $volt->getCompiler();
$compiler->addFunction('pagination_url', function ($resolvedArgs, $exprArgs) use ($compiler) {
$url = $compiler->expression($exprArgs[0]['expr']);
$page = $compiler->expression($exprArgs[1]['expr']);
return $url . '.\'?\'.http_build_query(array_merge($this->request->getQuery(), [\'page\' => ' . $page . ']))';
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.