首页 > 解决方案 > 银条 $Children.Filter

问题描述

我正在使用 Silverstripe 和 Silvershop 模块开发电子商务解决方案。我想在我的商店页面的顶层显示所有产品,分为几类(T 恤、帽子、程序......)。目前,我得到了单独的“ProductCategories”,但每个类别都显示所有子页面(“产品”)的列表,而不是每个类别的相关子页面。

我使用的过滤器设置如下:

<% loop $Children.Filter('ClassName', 'ProductCategory') %>

任何人都可以就为什么这不起作用提供建议吗?

标签: filteringe-commerceparent-childsilverstripechildren

解决方案


你可以试试类似的东西。

PHP

function ProductCategoryList() {
  return ProductCategory::get();
}

模板

<% if $ProductCategoryList %>
  <% loop $ProductCategoryList %>
    <h2>$Title</h2>
    <% loop $ProductsShowable %>
      <div class="product">
        <h3>$Title</h3>
        <div>$Content</div>
      </div>
    <% end_loop %>
  <% end_loop %>
<% end_if %>

推荐阅读