filtering - 银条 $Children.Filter
问题描述
我正在使用 Silverstripe 和 Silvershop 模块开发电子商务解决方案。我想在我的商店页面的顶层显示所有产品,分为几类(T 恤、帽子、程序......)。目前,我得到了单独的“ProductCategories”,但每个类别都显示所有子页面(“产品”)的列表,而不是每个类别的相关子页面。
我使用的过滤器设置如下:
<% loop $Children.Filter('ClassName', 'ProductCategory') %>
任何人都可以就为什么这不起作用提供建议吗?
解决方案
你可以试试类似的东西。
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 %>
推荐阅读
- tree - 具有 cplex-opl 的最小生成树
- sql - 如何最好地拆分数据库表?
- gradle - 无法理解 Gradle 的默认依赖解析策略
- python - 如何在python中将部分api响应转换为完整的json
- javascript - 简化这个 if 语句
- java - 从 Apache 访问静态 Spring Boot 文件
- html - 我的立场:粘性不起作用,有什么想法吗?
- cors - 带有 Cloud Run CORS 的 Google Api 网关
- javascript - React-Hook-Form:未提交未选中的复选框
- javascript - 无法读取未定义的属性“长度” - JavaScript 中的错误