【发布时间】:2016-12-16 10:07:40
【问题描述】:
我有一个自定义内容类型,其中包含价格、产品摘要、产品图片等多个字段。有什么方法可以在搜索结果页面上单独访问这些字段?
我使用kint(item.value) 在mytheme/item-list.html.twig 上打印了渲染数组,这表明我只能分别访问title、url 和type,如{{ item.value['#result'].url }}、{{ item.value['#result'].title }}。但在渲染数组中看不到product_image、product_summary 等变量。
根据 Twig 模板建议,我需要覆盖的模板是 search-result.html.twig。所以我将/core/themes/stable/templates/content/search-result.html.twig 复制到我的主题文件夹中。但是,{{ snippet }} 变量没有我想要访问的信息。
我通过以下步骤自定义结果输出:
- 去了
/admin/structure/types/manage/product/display(Structure > Content Types > Product > Manage Display)。打开Search Index和Search result highlight input。
- 导航到
Search result highlight input选项卡并添加(启用)两个字段产品摘要和产品价格
- 返回搜索结果,但我仍然看不到渲染数组中的那些变量。
有人可以告诉我完成上述任务的最佳方法吗?
【问题讨论】:
标签: twig drupal-theming drupal-8