listorchardcmsorchardcms-1.6orchardcms-1.7orchardcms-1.8

Customize list rendering for pagination


i'm trying to implement infinite scroll in Orchard doing minimal changes.

The script I use need to perfectly identify with a jquery selector the Next page link of pager.

Currently a standard orchard pager renders this way:

<li><a href="/OrchardLocal/ricette?page=2">&gt;</a></li>

the desiderable rendering is:

<li class="next"><a href="/OrchardLocal/ricette?page=2">&gt;</a></li>

I tried many ways to override the Pager_Next template but no joy. The pager is a list and list is done by code. No easy way to override.

A great article the should explain how to do miss some basic part (as to override the whole list for example): http://weblogs.asp.net/bleroy/overriding-the-pager-rendering-in-orchard

Right now my workaround was to change the Orchard source CoreShapes.cs for list rendering adding these two lines:

if (itemTag != null) {
  if (index == 0)
    itemTag.AddCssClass("first");
  if (index == count - 1)
    itemTag.AddCssClass("last");

  //new lines
  if (index == 1 && count > 2)
    itemTag.AddCssClass("previous");
  if (index == count - 2 && count > 2)
     itemTag.AddCssClass("next");

So far it works BUT I do not like it

1) It changes orchard source, this is bad

2) It changes all the lists (and not just pager)

So "How may I override the list for JUST my theme and for JUST pager in a way that a class is added automatically at the Page_Next li tag?"

Thanks


Solution

  • Try something like this in your Pager.Next.cshtml alternate view:

    @using System.Web.Routing;
    @{
        string text = Model.Value.ToString();
        string action = Model.RouteValues["action"].ToString();
        RouteValueDictionary routeValues = (RouteValueDictionary)Model.RouteValues;
    }
    
    <span><a class="next" href="@Url.Action(action, routeValues)">@text</a></span>