首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shop名称的液体If语句

Shop名称的液体If语句
EN

Stack Overflow用户
提问于 2020-04-12 00:06:05
回答 1查看 925关注 0票数 1

我有我的品牌或商店名称添加到我的所有网址通过以下语句,这是在theme.liquid文件中找到的。我想排除所有的网页,是博客或文章。这意味着在这些URL上没有商店名,这就是这个管道和代码。

代码语言:javascript
复制
| {{ shop.name }}

原始代码

代码语言:javascript
复制
  {%- capture seo_title -%}
    {%- if template == 'search' and search.performed == true -%}
      {{ 'general.search.heading' | t: count: search.results_count }}: {{ 'general.search.results_with_count' | t: terms: search.terms, count: search.results_count }}
    {%- else -%}
      {{ page_title }}
    {%- endif -%}
    {%- if current_tags -%}
      {%- assign meta_tags = current_tags | join: ', ' -%} – {{ 'general.meta.tags' | t: tags: meta_tags -}}
    {%- endif -%}
    {%- if current_page != 1 -%}
      – {{ 'general.meta.page' | t: page: current_page }}
    {%- endif -%}
    {%- assign escaped_page_title = page_title | escape -%}
    {%- unless escaped_page_title contains shop.name -%}
      | {{ shop.name }}
    {%- endunless -%}
  {%- endcapture -%}
    <title>{{ seo_title | strip }}</title>

我一直试图把另一个if声明围绕以下内容,但我还没有运气。

代码语言:javascript
复制
    {%- assign escaped_page_title = page_title | escape -%}
    {%- unless escaped_page_title contains shop.name -%}
      &#124; {{ shop.name }}
    {%- endunless -%}

这是我尝试过的代码,是否有更好的方法来做到这一点,因为我不能完全让它工作。

尝试代码

代码语言:javascript
复制
  {%- capture seo_title -%}
    {%- if template == 'search' and search.performed == true -%}
      {{ 'general.search.heading' | t: count: search.results_count }}: {{ 'general.search.results_with_count' | t: terms: search.terms, count: search.results_count }}
    {%- else -%}
      {{ page_title }}
    {%- endif -%}
    {%- if current_tags -%}
      {%- assign meta_tags = current_tags | join: ', ' -%} &ndash; {{ 'general.meta.tags' | t: tags: meta_tags -}}
    {%- endif -%}
    {%- if current_page != 1 -%}
      &ndash; {{ 'general.meta.page' | t: page: current_page }}
    {%- endif -%}
    {%- if (template == "blog" or template == "article") and current_tags contains '_NOINDEX' -%}
    {%- assign escaped_page_title = page_title | escape -%}
    {%- unless escaped_page_title contains shop.name -%}
    {%- endunless -%}
    {%- else -%}
    {%- assign escaped_page_title = page_title | escape -%}
    {%- unless escaped_page_title contains shop.name -%}
      &#124; {{ shop.name }}
    {%- endunless -%}
   {%- endif -%}
  {%- endcapture -%}
    <title>{{ seo_title | strip }}</title>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-12 04:38:10

您只需使用以下内容:

代码语言:javascript
复制
 {%- unless escaped_page_title contains shop.name or template == 'blog' or template == 'article' -%}
   &#124; {{ shop.name }}
 {%- endunless -%}

您已接近,但不能使用括号对液体条件运算符进行分组。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61165215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档