-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Closed
Labels
Description
The \Magento\Theme\Block\Html\Pager
class does not support "fragments" for generating urls like some-page/?p=2#fragment-here
.
Here are some scenarios when this might be needed.
- A category page has an image and a description and below that the products. Most likely the customer reads the description on the first page he visits and will not care about seeing it again on the second page. So I may want, when he clicks on the second page, to auto scroll to the start of the products list. I know this can be achieved by javascript, but a native support would be nice.
- I may have a page that has 2 paginated lists (they may be in separate tabs) and when I change the page for one of the list I want the autoscroll (or the selection of a specific tab) to be done via the url fragment.
This can be achieved simply by adding in the \Magento\Theme\Block\Html\Pager
class a protected member:
protected $fragment = null;
2 methods:
public function getFragment()
{
return $this->fragment;
}
public function setFragment($fragment)
{
$this->fragment = $fragment;
return $this;
}
and a change is needed for the getPagerUrl
method to include the fragment:
public function getPagerUrl($params = [])
{
$urlParams = [];
$urlParams['_current'] = true;
$urlParams['_escape'] = true;
$urlParams['_use_rewrite'] = true;
$urlParams['_fragment'] = $this->getFragment(); //this needs to be added
$urlParams['_query'] = $params;
return $this->getUrl('*/*/*', $urlParams);
}
I could do a PR for this, but I wanted first to get your opinion and to see if you may already have this planned.