index

index 模板用来渲染商店的首页,位置在根 URL (/)。首页通常是客户对商店的第一印象,所以 index 模板应该提供多种选项,方便商家讲述自己的故事。

小提示

可以参考 Dawn 主题里的 index template 作为示例。

首页模板 - index 模板 - 图1

位置

index 模板位于主题的 templates 目录下:

  1. └── theme
  2. ├── layout
  3. ├── templates
  4. | ...
  5. | ├── index.json
  6. | ...
  7. ...

使用方法

在使用 index 模板时,你需要了解 JSON 和 Liquid index 模板的区别

JSON vs. Liquid

JSON 和 Liquid 的 index 模板都允许商家通过主题编辑器添加和删除 section。虽然 Liquid index 模板也有这个功能,但大多数情况下,你应该使用 JSON 模板 (index.json) 作为你的 index 模板。JSON 模板相比 Liquid 模板有以下优点:

  • JSON 模板可以让商家更灵活地添加、删除和重新排序 section,包括 app section。
  • JSON 模板可以自己存储数据,能减少 settings_data.json 中的数据量,从而提升主题编辑器的性能。