为什么不在Shopify中使用块标签来处理Liquid?

huangapple go评论47阅读模式
英文:

Why not use block tags for Liquid in Shopify?

问题

我在我的Shopify模板中找到了这个片段,其中有一组标记来标记多个Liquid语句。我很高兴不必把所有的Liquid代码都包裹在单独的{% %}标记中。为什么不经常使用这种风格?

这是出于偏好还是有技术原因要避免呢?

英文:

I found this snippet in my Shopify template, with a single set of tags demarking multiple liquid statements. I'm excited to not have to wrap all of my liquid code in individual {% %} tags. Why is style this not used more often?

Is it just preference, or is there a technical reason to avoid it?

{%- liquid
  assign isModal = false
  if template == 'product.modal'
    assign isModal = true
  endif
-%}

答案1

得分: 1

Liquid语言已经发展并持续发展为一个模板语言。当它首次发布时,只能执行特定模式。随着它的发展,随着新的关键词和支持解析器的发布,执行新模式变得更容易。Liquid是开源的,因此许多人已经采用它并对其进行了增强。当Shopify看到其他人做一些好的事情时,他们通常会采用它用于他们的Liquid。总之,长话短说,你确实可以打开一个Liquid块,编写一些语句,然后关闭它。我们还进行了长时间而多样化的辩论,以使注释更加友好。现在你也可以利用更友好的注释结构。进步!

没有技术原因需要避免完全合法的标签使用。最终,Shopify的机器会将所有Liquid压缩并解析为一个巨大的HTML字符串,并将其全部发送到浏览器,不必担心是作为一个块还是一堆较小的块来完成某项任务。

英文:

Liquid has evolved and continues to evolve as a template language. When it was first released, one could only do certain patterns. As it evolved, it became easier to do new patterns as new keywords and supporting parsers were released. Liquid is open source and so many have adopted it and enhanced it too. When Shopify sees others doing something nice, they often adopt it for their Liquid. Anyway, long story short, you can indeed open up a Liquid block, write some statements, and then close it off. We also had a long and varied debate on making comments nicer. You can take advantage of nicer comment structures now too. Progress!

There is no technical reason to avoid perfectly legit tag usage. At the end of the day, the Shopify machine compresses and parses all that Liquid into a single huge string of HTML and dumps it all to the browser, no worries about you issuing as one block or a bunch of smaller ones to get something done.

huangapple
  • 本文由 发表于 2023年2月14日 06:31:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75441805.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定