2016-04-09 9 views
0

私はDotLiquidテンプレートエンジンを使用して、アプリケーションでのテーマ設定を可能にしています。ドット液体内のアクセスコレクションのプロパティ

内では、セーフタイプとして登録されているListから継承されたページネーションされたリストがあり、メンバー内のメンバーにアクセスできます。 PaginatedListはアプリケーションの上位層から来ており、Dot Liquidが使用されていることを知らないため、Dropを継承する代わりにRegisterSafeTypeを使用します。

 Template.RegisterSafeType(typeof(PaginatedList<>), new string[] { 
      "CurrentPage", 
      "HasNextPage", 
      "HasPreviousPage", 
      "PageSize", 
      "TotalCount", 
      "TotalPages" 
     }); 

public class PaginatedList<T> : List<T> 
{ 
    /// <summary> 
    /// Returns a value representing the current page being viewed 
    /// </summary> 
    public int CurrentPage { get; private set; } 

    /// <summary> 
    /// Returns a value representing the number of items being viewed per page 
    /// </summary> 
    public int PageSize { get; private set; } 

    /// <summary> 
    /// Returns a value representing the total number of items that can be viewed across the paging 
    /// </summary> 
    public int TotalCount { get; private set; } 

    /// <summary> 
    /// Returns a value representing the total number of viewable pages 
    /// </summary> 
    public int TotalPages { get; private set; } 

    /// <summary> 
    /// Creates a new list object that allows datasets to be seperated into pages 
    /// </summary> 
    public PaginatedList(IQueryable<T> source, int currentPage = 1, int pageSize = 15) 
    { 
     CurrentPage = currentPage; 
     PageSize = pageSize; 
     TotalCount = source.Count(); 
     TotalPages = (int)Math.Ceiling(TotalCount/(double)PageSize); 

     AddRange(source.Skip((CurrentPage - 1) * PageSize).Take(PageSize).ToList()); 
    } 

    /// <summary> 
    /// Returns a value representing if the current collection has a previous page 
    /// </summary> 
    public bool HasPreviousPage 
    { 
     get 
     { 
      return (CurrentPage > 1); 
     } 
    } 

    /// <summary> 
    /// Returns a value representing if the current collection has a next page 
    /// </summary> 
    public bool HasNextPage 
    { 
     get 
     { 
      return (CurrentPage < TotalPages); 
     } 
    } 
} 

このリストは、local.Productsのビューに公開され、ドット・リキッドのコレクションは繰り返し機能します。

ただし、内部のプロパティにアクセスしようとしていますが、エラーは発生していませんが、ドット・リキッドに置き換えられている値はありません。

私は私が間違っているつもりですどこ誰もが見ることができる

| 

に置き換えられ

{{ local.Products.CurrentPage }} | 

を使用していますか?

答えて

1

私はあなたのコードに問題はないと思っていますが、それはDotLiquid(およびLiquid)がリストとコレクションをどのように処理するかの限界です。 IIRCでは、リストやコレクションの任意のプロパティにアクセスすることはできません。

PaginatedList<T>を変更して、それを継承するのではなくList<T>が含まれるようにテストできます。

+0

ありがとうTim、これはそうだと思われます。 – EverythingGeek

関連する問題