Layouts

Layouts是主题的基础,通过它呈现所有Templates

你可以编辑默认的theme.liquid layout,或者创建创建多个自定义layout文件以满足您的需要。您还可以将模板设置为不使用layout。

模板结构 - 图1

文件位于layout目录下

  1. └── theme
  2. ├── layout
  3. | ├── theme.liquid
  4. | ...
  5. ├── templates
  6. ...

Schema

因为layout文件是主题的基础,所以在大多数情况下它们应该遵循标准 HTML 文档的结构大多数layout文件还包含以下 Liquid 对象:
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. ...
  5. {{ content_for_header }}
  6. ...
  7. </head>
  8. <body>
  9. ...
  10. {{ content_for_layout }}
  11. ...
  12. </body>
  13. </html>

模板结构 - 图2

Templates

模板结构 - 图3

文件位于templates目录下

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

文件类型

JSON 与 Liquid

如果要在模板中使用section,则应使用 JSON 模板。 JSON 模板为商家添加、删除和重新排序部分(包括应用部分)提供了更大的灵活性。此外,它们最大限度地减少了settings_data.json 中的数据量。相反,数据直接存储在模板中,这提高了主题编辑器的性能。

Templates类型

Type Description
404 Renders page content that is shown to customers if they enter an invalid URL for the store.
article Renders the article page, which contains the full content of the article, as well as an optional comments section for customers. This template is used for items like individual posts in a blog.
blog Renders the blog page, which lists all articles within a blog.
cart Renders the /cart page, which provides an overview of the contents of a customer’s cart.
collection Renders the collection page, which lists all products within a collection.
customers/account Renders the customer account page, which provides an overview of the customer’s account.
customers/activate_account Renders the customer account activation page, which hosts the form for activating a customer account.
customers/addresses Renders the customer addresses page, which allows customers to view and manage their current addresses, as well as add new ones.
customers/login Renders the customer login page, which hosts the form for logging into a customer account.
customers/order Renders the customer order page, which displays the details of a customer’s past orders.
customers/register Renders the customer register page, which hosts the form for customer account creation.
customers/reset_password Renders the password reset page, which hosts the form to reset the password for a customer account.
gift_card.liquid Renders the gift card page, which displays the gift card issued to a customer upon purchase. This must be a Liquid template.
index Renders the home page of the store, located at the root URL (/).
list-collections Renders the collection list page, which lists all the store’s collections. This page is located at the /collections URL of the store.
page Renders the shop’s pages, such as About us and Contact us.
password Renders the /password page, which is a landing page shown when you add password protection to your online store
. This page includes a message that is editable by merchants, and the password form for customers to gain access to the store.
product Renders the product page, which contains a product’s media and content, as well as a form for customers to select a variant and add it to the cart.
robots.txt.liquid Renders the robots.txt file, which is hosted at the /robots.txt URL. This file tells search engines which pages can, or can’t, be crawled on a site. This must be a Liquid template.
search Renders the /search page, which displays the results of a storefront search
.

Sections

模板结构 - 图4

文件位于sections目录下

  1. └── theme
  2. ...
  3. ├── templates
  4. ├── sections
  5. ...

内容

Type Description Required
Main content Any HTML or Liquid content you might want to include in the section.
Sections have the same access to global objects, tags, and filters as other Liquid theme files, as well as the following section-specific objects:
+ The** section object - Contains the section’s properties and setting values.
+
The** block object - Contains the properties and setting values of a single section block.
Aside from global objects, variables created outside of sections aren’t accessible within sections.
The section and block objects, as well as variables created within sections, aren’t available outside of their respective section. The only exception is when you reference section and block objects within a snippet that’s rendered inside the section you’re referencing.
No
Assets Sections can bundle their own JavaScript and stylesheet assets with the following section-specific Liquid tags:
+ {% javascript %}
+ {% stylesheet %}
To learn more, refer to Section assets.
No
Schema Sections support the section-specific {% schema %} Liquid tag. This tag is used to define the following section attributes and settings:
+ name
+ tag
+ class
+ settings
+ blocks
+ app blocks
+ max_blocks
+ presets
+ defaults
+ locales
+ templates
To learn more, refer to Section schema.
Yes

Section schema

name

该属性确定模板编辑器中显示的section标题。
  1. {% schema %}
  2. {
  3. "name": "Slideshow"
  4. }
  5. {% endschema %}

模板结构 - 图5

tag、class、settings、blocks

  1. {% schema %}
  2. {
  3. "name": "Slideshow",
  4. "tag": "section",
  5. "class": "slideshow",
  6. "settings": [
  7. {
  8. "type": "text",
  9. "id": "title",
  10. "label": "Slideshow"
  11. }
  12. ],
  13. "blocks": [
  14. {
  15. "name": "Slide",
  16. "type": "slide",
  17. "settings": [
  18. {
  19. "type": "image_picker",
  20. "id": "image",
  21. "label": "Image"
  22. }
  23. ]
  24. }
  25. ]
  26. }
  27. {% endschema %}
Blocks 有以下属性需要注意:
Attribute Description Required
type The block type. This is a free-form string that you can use as an identifier. You can access this value through the type attribute of the Liquid block object
.
Yes
name The block name, which will show as the block title in the theme editor. Yes
limit The number of blocks of this type that can be used. No
settings Any settings
that you want for the block. Certain settings might be used as the title of the block in the theme editor
.
No

渲染blocks

  1. {% for block in section.blocks %}
  2. {% case block.type %}
  3. {% when 'slide' %}
  4. <div class="slide" {{ block.shopify_attributes }}>
  5. {{ block.settings.image | img_url: '2048x' | img_tag }}
  6. </div>
  7. ...
  8. {% endcase %}
  9. {% endfor %}

max_blocks

每个section最大可以放16个block,也可以通过max_blocks 属性设置。

  1. {% schema %}
  2. {
  3. "name": "Slideshow",
  4. "tag": "section",
  5. "class": "slideshow",
  6. "max_blocks": 5,
  7. "settings": [
  8. {
  9. "type": "text",
  10. "id": "title",
  11. "label": "Slideshow"
  12. }
  13. ],
  14. "blocks": [
  15. {
  16. "name": "Slide",
  17. "type": "slide",
  18. "settings": [
  19. {
  20. "type": "image_picker",
  21. "id": "image",
  22. "label": "Image"
  23. }
  24. ]
  25. }
  26. ]
  27. }
  28. {% endschema %}

模板结构 - 图6

presets与default

Section可以设定一些默认设置,让商家编辑起来更轻松。

presets和default区别

presets预设值以后后面还可以改,default设置了以后后面不能改。

presets和default对象都具有以下属性:

Attribute Description Required
name The preset name, which will show in the Add section portion of the theme editor. Yes
settings A list of default values for any settings you might want to populate. Each entry should include the setting name and the value. No
blocks A list of default blocks that you might want to include. Each entry should be an object with attributes of type and settings. The type attribute value should reflect the type of the block that you want to include, and the settings object should be in the same format as the settings attribute above. No
  1. {% schema %}
  2. {
  3. "name": "Slideshow",
  4. "tag": "section",
  5. "class": "slideshow",
  6. "max_blocks": 5,
  7. "settings": [
  8. {
  9. "type": "text",
  10. "id": "title",
  11. "label": "Slideshow"
  12. }
  13. ],
  14. "blocks": [
  15. {
  16. "name": "Slide",
  17. "type": "slide",
  18. "settings": [
  19. {
  20. "type": "image_picker",
  21. "id": "image",
  22. "label": "Image"
  23. }
  24. ]
  25. }
  26. ],
  27. "presets": [
  28. {
  29. "name": "Slideshow",
  30. "settings": {
  31. "title": "Slideshow"
  32. },
  33. "blocks": [
  34. {
  35. "type": "slide"
  36. },
  37. {
  38. "type": "slide"
  39. }
  40. ]
  41. }
  42. ]
  43. }
  44. {% endschema %}

模板结构 - 图7

Section assets

javascript

  1. {% javascript %}
  2. document.querySelector('.slideshow').slideshow();
  3. {% endjavascript %}

每个section只能有一个{% javascript %} tag。

stylesheet

  1. <div class="slideshow-wrapper" data-slide-speed="{{ section.settings.speed }}">
  2. <!-- slideshow content -->
  3. </div>
  4. {% stylesheet %}
  5. .slideshow-wrapper {
  6. // your styles
  7. }
  8. {% endstylesheet %}

每个section只能有一个{% stylesheet %} tag。

Settings

Input settings

属性

Attribute Description Required
type The setting type, which can be any of the basic
or specialized
input setting types.
Yes
id The setting ID, which is used to access the setting value. Yes
label The setting label, which will show in the theme editor. Yes
default The default value for the setting. No
info An option for informational text about the setting. No

Basic input settings

The following are the basic input setting types:

checkbox

  1. {
  2. "type": "checkbox",html
  3. "id": "show_announcement",
  4. "label": "Show announcement",
  5. "default": true
  6. }

模板结构 - 图8

number

  1. {
  2. "type": "number",
  3. "id": "products_per_page",
  4. "label": "Products per page",
  5. "default": 20
  6. }

模板结构 - 图9

select

  1. {
  2. "type": "select",
  3. "id": "vertical_alignment",
  4. "label": "Vertical alignment",
  5. "options": [
  6. {
  7. "value": "top",
  8. "label": "Top"
  9. },
  10. {
  11. "value": "middle",
  12. "label": "Middle"
  13. },
  14. {
  15. "value": "bottom",
  16. "label": "Bottom"
  17. }
  18. ],
  19. "default": "middle"
  20. }

模板结构 - 图10

Specialized input settings

The following are the specialized input setting types:

article

  1. {
  2. "type": "article",
  3. "id": "featured_article",
  4. "label": "Featured article"
  5. }

模板结构 - 图11

blog

  1. {
  2. "type": "blog",
  3. "id": "blog",
  4. "label": "Blog"
  5. }

模板结构 - 图12

collection

  1. {
  2. "type": "collection",
  3. "id": "collection",
  4. "label": "Collection"
  5. }

模板结构 - 图13

color

  1. {
  2. "type": "color",
  3. "id": "body_text",
  4. "label": "Body text",
  5. "default": "#000000"
  6. }

模板结构 - 图14

color_background

  1. {
  2. "type": "color_background",
  3. "id": "background",
  4. "label": "Background",
  5. "default": "linear-gradient(#ffffff, #000000)"
  6. }

模板结构 - 图15

font_picker

  1. {
  2. "type": "font_picker",
  3. "id": "heading_font",
  4. "label": "Heading font",
  5. "default": "helvetica_n4"
  6. }

模板结构 - 图16

html

  1. {
  2. "type": "html",
  3. "id": "video_embed",
  4. "label": "Video embed"
  5. }

模板结构 - 图17

image_picker

  1. {
  2. "type": "image_picker",
  3. "id": "logo_image",
  4. "label": "Logo image"
  5. }

模板结构 - 图18

link_list

  1. {
  2. "type": "link_list",
  3. "id": "menu",
  4. "label": "Menu"
  5. }

liquid

  1. {
  2. "type": "liquid",
  3. "id": "battery_message",
  4. "label": "Battery message",
  5. "default": "This product can be shipped by ground or air."
  6. }

模板结构 - 图19

page

  1. {
  2. "type": "page",
  3. "id": "page",
  4. "label": "Page"
  5. }

模板结构 - 图20

product

  1. {
  2. "type": "product",
  3. "id": "product",
  4. "label": "Product"
  5. }

模板结构 - 图21

richtext

  1. {
  2. "type": "richtext",
  3. "id": "paragraph",
  4. "label": "Paragraph"
  5. }

模板结构 - 图22

Sidebar settings

侧边栏设置不能保存值且不可配置。它们是信息元素,可用于提供有关输入设置的详细信息并对其进行组织。 侧边栏设置由标准属性组成。以下是侧边栏设置的类型:

header

  1. {
  2. "type": "header",
  3. "content": "Announcement bar"
  4. }

模板结构 - 图23

paragraph

  1. {
  2. "type": "paragraph",
  3. "content": "All of your collections are listed by default. To customize your list, choose 'Selected' and add collections."
  4. }

模板结构 - 图24

Fonts

您可以通过以下方式向主题添加字体:
  1. 使用 Shopify 字体库中的字体
  2. 使用自定义字体
一般而言,字体是一种单独的资源,需要在呈现任何文本之前由浏览器下载,这会影响商店的整体性能。为了提高主题的性能,从 Shopify 字体库的系统字体类别中选择字体的商家可以使用客户计算机上已安装的系统字体。