Snippets are simply a way to make code neater.
代码段往往可以让我们的代码更加简洁易用。

If some code is getting really long, I can save it inside a snippet. I can then render that snippet inside of another file. Think of it like a folder structure for code.
如果某些代码很长,我们可以把它保存进代码段里面。之后我们可以在其它文件里渲染出这个代码段。我们可以把代码段想象为一个即插即用的U盘,放置到相应的位置就会出现对应的内容。
Example:
举例:
I’m working on a theme that can display social icons in many places – in the footer or in the header.
如果我们想在主题的头部或者是底部展示社媒图标,

My code for the social icons is quite long – we have a list of 10 social networks with the icon and link for each.
如上图所示,我们有十几个社媒图标,并且每一个都有对应的链接。这就导致我们的这段代码非常长。
So I save all that code in a snippet called social-icons.liquid. Now I can include it inside footer.liquid and header.liquid with just one line:

因此我们可以把这段长长的社媒代码保存为一个social-icons.liquid 的文件。之后我们只需要在footer.liquid或者 header.liquid文件里引用social-icons.liquid代码段就可以轻松加上社媒代码了。




