简体   繁体   English

Shopify Liquid If 商店名称语句

[英]Shopify Liquid If Statement for Shop Name

I have my brand name or shop name added to all my URL's via the following statement which is found in the theme.liquid file.我通过 theme.liquid 文件中的以下语句将我的品牌名称或商店名称添加到我的所有 URL 中。 I want to exclude all pages that are blogs or articles.我想排除所有博客或文章页面。 This would mean no shop name on those URL's, which is this pipe and code.这意味着这些 URL 上没有商店名称,即 pipe 和代码。

| {{ shop.name }}

Original Code原始代码

  {%- 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>

I have been trying to place another if statement around the following but I have had no luck yet.我一直试图在下面放置另一个 if 语句,但我还没有运气。

    {%- assign escaped_page_title = page_title | escape -%}
    {%- unless escaped_page_title contains shop.name -%}
      &#124; {{ shop.name }}
    {%- endunless -%}

This is the code that I have tried, is there a better way to do this as I can't quite get it to work.这是我尝试过的代码,有没有更好的方法来做到这一点,因为我不能让它工作。

Attempted Code尝试的代码

  {%- 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>

You can just use the following:您可以使用以下内容:

 {%- unless escaped_page_title contains shop.name or template == 'blog' or template == 'article' -%}
   &#124; {{ shop.name }}
 {%- endunless -%}

You were close, but you cannot use parentheses to group Liquid condition operators.您很接近,但您不能使用括号对 Liquid 条件运算符进行分组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM