重用带有自定义视图模型的 Umbraco 网格

Reuse umbraco grid with custom viewmodel

我是新的 Umbraco 网格功能的新手,对此我有疑问。

我有一个包含文章的页面,我在其中使用网格功能显示除该图像之外的一些图像和文本。这工作正常。

在该页面的属性中,我放了一个复选框,用于说明该文章是否出售,选中后产品应自动出现在出售页面上。

我可以在该页面上获得正在销售的产品,但现在我还想在该页面上显示图像和文字。我创建了一个带有自定义视图模型的列表来保存每个待售产品的内容。问题在于将 JObject 提供给 GetGridHtml 函数。此函数需要一个字符串,而我提供了导致错误的 属性。

让网格内容显示在该单独页面上的最佳方法是什么?

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
     var home = CurrentPage.Site();

     List<ForSaleItemsViewModel> forSaleItemsVM = new List<ForSaleItemsViewModel>();

     if(home.Children.Any())
     {        
         foreach(var childPage in home.Children)
         {
             if(childPage.Children.Any())
             {
                 foreach(var child in childPage.Children)
                 {
                     if(child.HasProperty("ForSale") && child.ForSale)
                     {
                           forSaleItemsVM.Add(new ForSaleItemsViewModel
                                            {
                                                ID = 1,
                                                Content = child.Content,
                                                Sold = child.Sold
                                            });
                     }
                }
            }
         }
    }
}

<div class="container">
    @foreach(var item in forSaleItemsVM)
    {
        if (item.Sold)
        {
            <span>SOLD!</span>
        }
        CurrentPage.GetGridHtml(item.Content.ToString(), "bootstrap3");
    }
</div>

根据 Umbraco 论坛,这是不可能的。我得到了这个答案:

If you see the documentation for best pratices for the grid layout https://our.umbraco.org/Documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors-v7/Grid-Layout-Best-Practices there is a chapter about the limitations for the grid layout https://our.umbraco.org/Documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors-v7/Grid-Layout-Best-Practices#Limitations. And of the limitions of using the grid layout is that it´s not for reused content.

It says - There is no managed api to drill into the grid content and target specific cell content - so a grid layout is not a recommended storage of reusable content - it simply wasn't designed for this scenario. If you wish to reuse content in multiple pages, it is still recommended that you store these pieces of content as seperate content nodes, so they can be stored, cached and queried as usual.