社区首页 >问答首页 >尝试在shopify中创建幻灯片显示变体

尝试在shopify中创建幻灯片显示变体
EN

Stack Overflow用户
提问于 2020-04-21 14:14:41
回答 1查看 1.3K关注 0票数 0

我是新的shopify,我试图创建一个网站与幻灯片显示变体。我已经成功地编写了这段代码,但是我得到了以下错误行247 -液体语法错误:“schema”标记不能嵌套在其他标记中。

该代码旨在使用应用flex应用程序将该变体创建为幻灯片放映。

有人知道我走错路了吗?

代码语言:javascript
代码运行次数:0
复制
 <!-- /templates/product.liquid -->
<div itemscope itemtype="http://schema.org/Product" id="ProductSection" data-section-id="{{ section.id }}" data-section-type="product-template" data-image-zoom-type="{{ section.settings.product_image_zoom_type }}" data-show-extra-tab="{{ section.settings.show_extra_tab }}" data-extra-tab-content="{{ section.settings.extra_tab_content }}" data-cart-enable-ajax="{{ settings.cart_enable_ajax }}" data-enable-history-state="true">

  <meta itemprop="name" content="{{ product.title }}">
  <meta itemprop="url" content="{{ shop.url }}{{ product.url }}">
  <meta itemprop="image" content="{{ product.featured_image.src | img_url: 'grande' }}">

  {% comment %}
    Get first variant in stock, or deep linked one
  {% endcomment %}
  {% assign current_variant = product.selected_or_first_available_variant %}
  {%- assign featured_image = current_variant.featured_image | default: product.featured_image -%}

  <div class="grid product-single">

    <div class="grid__item medium-up--one-half">
      {% for image in product.images %}
        {% capture img_id %}ProductImage-{{ image.id }}{% endcapture %}
        {% capture wrapper_id %}ProductImageWrapper-{{ image.id }}{% endcapture %}
        {%- assign img_url = image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' -%}

        {% include 'image-style' with image: image, width: 720, height: 600, small_style: true, wrapper_id: wrapper_id, img_id: img_id %}

        <div id="{{ wrapper_id }}" class="product-single__featured-image-wrapper supports-js{% unless featured_image == image %} hidden{% endunless %}" data-image-id="{{ image.id }}">
          <div class="product-single__photos" data-image-id="{{ image.id }}" style="padding-top:{{ 1 | divided_by: image.aspect_ratio | times: 100}}%;">
            <img id="{{ img_id }}"
                 class="product-single__photo lazyload{% unless featured_image == image %} lazypreload{% endunless %}{% if section.settings.product_image_zoom_type == 'lightbox' %} lightbox{% endif %}"
                 {% if section.settings.product_image_zoom_type == 'zoom-in' %} data-zoom="{{ image | img_url: '1024x1024' }}"{% endif %}
                 src="{{ image | img_url: '200x200' }}"
                 data-src="{{ img_url }}"
                 data-widths="[180, 360, 470, 600, 750, 940, 1080, 1296, 1512, 1728, 2048]"
                 data-aspectratio="{{ image.aspect_ratio }}"
                 data-sizes="auto"
                 alt="{{ image.alt | escape }}">
          </div>
          {% if product.compare_at_price_max > product.price %}
            <span class="badge badge--sale"><span>{{ 'products.product.on_sale' | t }}</span></span>
          {% endif %}
        </div>
      {% endfor %}

      <noscript>
        <img src="{{ featured_image | img_url: 'grande' }}" alt="{{ featured_image.alt | escape }}">
      </noscript>

      {% if product.images.size > 1 %}
        <ul class="product-single__thumbnails grid grid--uniform" id="ProductThumbs">

          {% case product.images.size %}
            {% when 2 %}
              {% assign thumbnail_width = 'small--one-half medium-up--push-one-sixth medium-up--one-third' %}
            {% when 4 %}
              {% assign thumbnail_width = 'small--one-half medium-up--one-quarter' %}
            {% else %}
              {% assign thumbnail_width = 'small--one-third medium-up--one-third' %}
          {% endcase %}

          {% for image in product.images %}
            <li class="grid__item {{ thumbnail_width }}">
              <a href="{{ image.src | img_url: 'grande' }}" class="product-single__thumbnail" data-image-id="{{ image.id }}">
                <img src="{{ image.src | img_url: 'compact' }}" alt="{{ image.alt | escape }}">
              </a>
            </li>
          {% endfor %}

        </ul>
      {% endif %}

      {% if section.settings.product_image_zoom_type == 'lightbox' %}
        <ul class="gallery hidden">
          {% for image in product.images %}
            <li data-image-id="{{ image.id }}" class="gallery__item" data-mfp-src="{{ image | img_url: '2048x2048' }}"></li>
          {% endfor %}
        </ul>
      {% endif %}
    </div>

    <div class="grid__item medium-up--one-half{% if product.images.size == 0%} medium-up--push-one-half{% endif %}">
      <div class="product-single__meta small--text-center">
        <h1 class="product-single__title" itemprop="name">{{ product.title }}</h1>

        {% if section.settings.vendor_show %}
          <p class="product-single__vendor" itemprop="brand">{{ product.vendor }}</p>
        {% endif %}

        <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
          <meta itemprop="priceCurrency" content="{{ cart.currency.iso_code }}">

          <link itemprop="availability" href="http://schema.org/{% if current_variant.available %}InStock{% else %}OutOfStock{% endif %}">

          <p class="product-single__prices">
            {% if product.compare_at_price_max > product.price %}
              <span id="ComparePriceA11y" class="visually-hidden">{{ 'products.product.sale_price' | t }}</span>
            {% else %}
              <span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
            {% endif %}
            <span id="ProductPrice" class="product-single__price" itemprop="price" content="{{ current_variant.price | divided_by: 100.00 }}">
              {{ current_variant.price | money }}
            </span>

            {% if product.compare_at_price_max > product.price %}
              <span id="PriceA11y" class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
              <s class="product-single__price--compare" id="ComparePrice">
                {{ current_variant.compare_at_price | money }}
              </s>
            {% endif %}

            {% include 'product-unit-price', variant: current_variant, available: true %}
          </p>

          {%- if shop.taxes_included or shop.shipping_policy.body != blank -%}
            <div class="product-single__policies rte">
              {%- if shop.taxes_included -%}
                {{ 'products.product.include_taxes' | t }}
              {%- endif -%}
              {%- if shop.shipping_policy.body != blank -%}
                {{ 'products.product.shipping_policy_html' | t: link: shop.shipping_policy.url }}
              {%- endif -%}
            </div>
          {%- endif -%}
          {%- assign productClasses = 'product-form' -%}
          {%- if product.has_only_default_variant -%}
            {%- assign productClasses = productClasses | append: ' product-form--default-variant-only' -%}
          {%- endif -%}

          {% form 'product', product, class: productClasses %}
            <select name="id" id="ProductSelect-{{ section.id }}" class="product-single__variants">
              {% for variant in product.variants %}
                {% if variant.available %}
                  <option {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %} data-sku="{{ variant.sku }}" value="{{ variant.id }}">{{ variant.title }} - {{ variant.price | money_with_currency }}</option>
                {% else %}
                  <option disabled="disabled">
                    {{ variant.title }} - {{ 'products.product.sold_out' | t }}
                  </option>
                {% endif %}
              {% endfor %}
            </select>

            {% if section.settings.product_quantity_enable %}
              <div class="product-single__quantity">
                <label for="Quantity">{{ 'products.product.quantity' | t }}</label>
                <input type="number" id="Quantity" name="quantity" value="1" min="1">
              </div>
            {% endif %}

            <div class="product-single__cart-submit-wrapper{% if section.settings.enable_payment_button %} product-single__shopify-payment-btn{% endif %}{% if section.settings.add_to_cart_width == 'full_width' %} product-form--full{% endif %}">
              <button type="submit" name="add" id="AddToCart" class="btn product-single__cart-submit{% if section.settings.add_to_cart_width == 'full_width' %} btn--full{% endif %}{% if section.settings.enable_payment_button %} shopify-payment-btn btn--secondary{% endif %}" data-cart-url="{{ routes.cart_url }}">
                <span id="AddToCartText">{{ 'products.product.add_to_cart' | t }}</span>
              </button>
              {% if section.settings.enable_payment_button %}
                {{ form | payment_button }}
              {% endif %}
            </div>

          {% endform %}

        </div>

        {% if section.settings.product_description_position == 'right' %}
          {%- assign position = 'right' -%}
          {% include 'product-description' %}
        {% endif %}

        {% if section.settings.social_sharing_products %}
          {% include 'social-sharing', share_title: product.title, share_permalink: product.url, share_image: product %}
        {% endif %}
      </div>
    </div>

  </div>

  {% if section.settings.product_description_position == 'below' %}
    {%- assign position = 'below' -%}
    {% include 'product-description' %}
  {% endif %}
</div>

{% unless product == empty %}
  <script type="application/json" id="ProductJson-{{ section.id }}">
    {{ product | json }}
  </script>
{% endunless %}

<script>
  // Override default values of shop.strings for each template.
  // Alternate product templates can change values of
  // add to cart button, sold out, and unavailable states here.
  window.productStrings = {
    addToCart: {{ 'products.product.add_to_cart' | t | json }},
    soldOut: {{ 'products.product.sold_out' | t | json }},
    unavailable: {{ 'products.product.unavailable' | t | json }}
  }
  {% if product.variants.size > 1 %}
<script>
(function($) {
  var variantImages = {},
    thumbnails,
    variant,
    variantImage,
    variantImage_count = 0;
    //produce mapping between variant image and options
    {% for variant in product.variants %}
       variant = {{ variant | json }};
       if ( typeof variant.featured_image !== 'undefined' && variant.featured_image !== null ) {
         variantImage =  variant.featured_image.src.split('?')[0].replace(/http(s)?:/,'');
         variantImages[variantImage] = variantImages[variantImage] || {};
         {% for option in product.options %}
           {% assign option_value = variant.options[forloop.index0] %}
           {% assign option_key = 'option-' | append: forloop.index0 %}
           if (typeof variantImages[variantImage][{{ option_key | json }}] === 'undefined') {
             variantImages[variantImage][{{ option_key | json }}] = {{ option_value | json }};
           }
           else {
             var oldValue = variantImages[variantImage][{{ option_key | json }}];
             if ( oldValue !== null && oldValue !== {{ option_value | json }} )  {
               variantImages[variantImage][{{ option_key | json }}] = null;
             }
           }
         {% endfor %}
         variantImage_count++;
       }
    {% endfor %}

    $(function() {

      if (variantImage_count > 0) {
        $('select.single-option-selector').change(function() {
          var selected_color = $(this).val();
          thumbnails = $('.flex-control-thumbs img').each(function(index, el) {
            var image = $(el).attr('src').split('?')[0].replace(/(_thumb\.)|(_small\.)|(_compact\.)|(_medium\.)|(_large\.)|(_grande\.)/,'.');
            if (typeof variantImages<div class="full"></div> !== 'undefined') {
              if(selected_color == variantImages<div class="full"></div>['option-0']) {
                //only check against the first option ['option-0'], which is Color (in my case)
                $('.flexslider').flexslider(index);
              }
            }
              });
        });
      }

    });
})(jQuery);
</script>

}
EN

回答 1

Stack Overflow用户

发布于 2020-04-22 05:05:56

标签是与Shopify的"分段主题“一起引入的。我可以看到您的shopify主题正在使用"Sections",因为您的代码中对section变量的所有引用!

由于在问题代码中搜索{% schema %}不会返回任何结果,所以我必须得出结论,语法错误起源于不同的文件。(可能包括带有product.liquid指令文件。

在关于"使用主题部分“的Shopify主题文档中,我们看到{% schema %}标记驻留在主题目录结构中的sections/文件夹中的模板中。在本例中,我希望在sections/product.liquid**.** 中找到导致语法错误的嵌套标记

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

https://stackoverflow.com/questions/61354161

复制
相关文章
Java在字符串中查找匹配的子字符串
示例: 在源字符串“You may be out of my sight, but never out of my mind.”中查找“my”的个数。输出:匹配个数为2
全栈程序员站长
2022/09/14
7.2K0
字符串中查找子串_cstring查找子字符串
假设要从主串 s = “goodgoogle” 中找到 t = “google” 子串。根据我们的思考逻辑,则有:
全栈程序员站长
2022/09/24
3K0
字符串中查找子串_cstring查找子字符串
java字符串的拆分_Java中的字符串分割 .
Java中的我们可以利用split把字符串按照指定的分割符进行分割,然后返回字符串数组,下面是string.split的用法实例及注意事项:
全栈程序员站长
2022/08/26
3.7K0
字符串匹配:字符串中查找某子串
我们在平时的软件开发,尤其是嵌入式开发,字符串匹配是非常重要的一个算法。而目前常用的字符串匹配算法有很多,下面就来介绍几个。
跋扈洋
2022/03/29
1.4K0
【SQL】查找给定字符串中包含已知子字符串
CREATE Function [dbo].[ConvertSyntax](@paraStr nvarchar(2000))
鲁郭大侠
2020/03/05
2.2K0
删除字符串中的子串
输入2个字符串S1和S2,要求删除字符串S1中出现的所有子串S2,即结果字符串中不能包含S2。
叶茂林
2023/07/28
2590
删除字符串中的子串
sscanf函数-----字符串拆分函数
sscanf的作用:从一个字符串中读进于指定格式相符的数据。利用它可以从字符串中取出整数、浮点数和字符串。 sscanf和scanf的区别:scanf是以键盘作为输入源,sscanf是以字符串作为输入源。
大忽悠爱学习
2021/03/02
3.3K0
sscanf函数-----字符串拆分函数
467. 环绕字符串中唯一的子字符串
假设有一个连续字符串 abcd,则他的非空子串的数量为 abc + 4,也等于 ab + 3 + 4。
程序员小航
2022/06/09
1.1K0
467. 环绕字符串中唯一的子字符串
LeetCode 2062. 统计字符串中的元音子字符串
元音子字符串 是 仅 由元音('a'、'e'、'i'、'o' 和 'u')组成的一个子字符串,且必须包含 全部五种 元音。
Michael阿明
2022/01/07
1.1K0
PowerShell:在 Windows 中创建并导出自签名证书
证书是一种包含公钥和一些识别信息的文件。在PKI中,证书是由可信任的第三方(称为证书颁发机构,CA)颁发的,CA证明了证书持有者的身份以及与之关联的公钥。然而,我们也可以创建自签名证书,即由证书持有者自己(而不是CA)签名的证书。
运维开发王义杰
2023/08/10
2.4K0
PowerShell:在 Windows 中创建并导出自签名证书
如何在 Bash 中抽取子字符串
本文介绍了如何在 Bash 中抽取子字符串,包括使用 IFS、cut 命令和编译自 Vivek Gite 的子字符串扩展方法。
企鹅号小编
2017/12/29
1.6K0
如何在 Bash 中抽取子字符串
python 如何使用split拆分字符串
将字符串拆分成一个列表,其中每个单词都是一个列表中的元素:txt = "welcome to the jungle"
用户8418197
2022/02/17
5K0
Python判断字符串是否包含子字符串
Python如何判断一个字符串是否包含指定字符串?本文介绍Python判断一个字符串是否包含指定子串的4种方法。具有一定的借鉴价值。
全栈程序员站长
2022/09/06
2K0
Python判断字符串是否包含子字符串
字符串——459. 重复的子字符串
示例 1: 输入: s = “abab” 输出: true 解释: 可由子串 “ab” 重复两次构成。
向着百万年薪努力的小赵
2022/12/02
1.4K0
讲究!字符串拆分还能这么玩
“哥,我感觉字符串拆分没什么可讲的呀,直接上 String 类的 split() 方法不就可以了!”三妹毫不客气地说。
沉默王二
2021/07/16
1K0
java——split的用法(字符串拆分)
从这里可以看到,本代码是用空格拆分字符串,但是最开始的字符串不会因为字符串的分割而改变(String定义的字符串不会被修改)
小雨的分享社区
2022/10/26
2K0
java——split的用法(字符串拆分)
R语言字符串处理①R语言字符串合并与拆分
R基础字符串处理函数 nchar paste strsplit tolower toupper casefold chartr gsub sub substr substring grep grepl regexpr R包stringr 字符串处理学习思路 拼接 对应拼接,如 (‘a’,’b’)+(‘c’,’d’) → (‘ac’,’bd’) 多拼为一,如 (‘a’,’cd’,’m’) → (‘acdm’) 拆分(根据pattern) 如’a.b.c.d’ → (‘a’,’b’,’
用户1359560
2018/08/27
6.5K0
R语言字符串处理①R语言字符串合并与拆分
MySQL字符串的合并及拆分
按照指定字符进行合并或拆分是经常碰到的场景,MySQL在合并的写法上比较简单,但是按指定字符拆分相对比较麻烦一点(也就是要多写一些字符)。本文将举例演示如何进行按照指定字符合并及拆分。
俊才
2020/07/01
6.4K0
mysql行转列(拆分字符串场景)
一对多没有建立中间表的时候经常会采用分隔符的形式将“多”存储在“一”的一个字段里,这样做的代价是无法像一对多的时候那样直接关联查询,一般采用在程序中分割后分别查询的办法。如下图:
全栈程序员站长
2022/09/03
2.5K0
mysql行转列(拆分字符串场景)
LeetCode刷题实战467:环绕字符串中唯一的子字符串
算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试。所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 !
程序员小猿
2021/12/15
5600

相似问题

Apache 2.4.x带宽配额/限制/速度

19

限制每个Apache虚拟主机的带宽

12

Coreplot限制带宽长度或限制带宽渲染顺序

13

限制带宽速度

30

Windows上Apache<2.2的带宽限制(mod_throttle?)

22
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档