![]() |
Hi everyone,
I was interested in adding an anchor to my pager links to make sure that when users navigate through their results, they don't have to scroll back down to them, but rather stay at the same page level. Better user experience... I thought I could add an anchor as a parameter maybe, but looking at the pager documentation, It does not look possible. I thought maybe I could pass a value to the template from my $viewData variable but when I tried, I got an 'undefined variable' error ; the template does not have access to my views variables? In the end I made it work this way: I created 2 different templates, one to be used in my bookings page, with the #bookings anchor I need, one in my presentations page where there are reviews, with the #reviews anchor I need and I select the template to be used in my controller or my view. It works but I feel there could be a better way to avoid having 2 template files where the only thing that changes is an anchor. Can you share your thoughts on the best way to do this?
Inside your template check The Request URL. That should allow you to determine on which page your template is being viewed and you can then determine which anchor to display based on the URL.
Alternatively, you could obtain the route information and use that in a similar fashion. Finally, it might be worth trying to include a View Partial within your pager template and pass the anchor parameter to it after having determined your required anchor. I'm unsure if this will work. More obviously, use one template and rename your anchor to #pager and make sure that the links on your page always travel to #pager regardless of whether they are on booking or review.
Thanks for your thoughts @grimpirate. I like the idea of a #pager anchor 'by default'. So simple yet I did not consider it just because I had bookings / reviews in my mind.
|
Welcome Guest, Not a member yet? Register Sign In |