Скрыть текст в описании продукта Shopify - PullRequest
0 голосов
/ 17 мая 2019

Просто ищу немного рекомендаций с Shopify. Я пытаюсь заключить текст в описание продукта в теги [#size] [/ size] (или аналогичные) ... чтобы затем захватить этот текст и поместить его во всплывающее окно.

Я выполнил большую часть работы, чтобы создать всплывающую кнопку, и всплывающее окно работает нормально, даже включая текст из описания продукта, однако текст в описании продукта остается там, а не скрывается во всплывающее окно, и я цепляюсь за соломинку, сейчас пытаюсь это исправить ...

Любые идеи будут высоко оценены, спасибо заранее.

Вот мой код в product-template.liquid

{% if product.description contains '[#size]' or product.description contains '[#video]' or product.description contains '[#other]' %}
      <div class="product-extra">
        {% if section.settings.show_product_size_chart and product.description contains '[#size]' %}
          {% assign shortcode_description = product.description | split: '[/size]' | first | split: '[#size]' | last %}
            <a class="product-size-chart fancybox" href="#product-size-chart"><i class="fas fa-ruler"></i> {{ 'products.product.sizing' | t }}
              <div id="product-size-chart" style="display: none;">
                {{ shortcode_description }}
              </div>
            </a>
        {% endif %}

        {% if section.settings.show_product_video and product.description contains '[#video]' %}
          {% assign shortcode_description = product.description | split: '[/video]' | first | split: '[#video]' | last %}
          <a class="product-video fancybox" href="#product-video"><i class="fas fa-play-circle"></i> {{ 'products.product.video' | t }}
            <div id="product-video" style="display: none;">
              {{ shortcode_description }}
            </div>
          </a>
        {% endif %}
        {% if section.settings.show_product_model and product.description contains '[#other]' %}
          <a class="product-model fancybox" href="#product-model"><i class="fas fa-info-circle"></i> {{ 'products.product.model' | t }}
            <div id="product-model" style="display: none;">
              {% assign shortcode_description = product.description | split: '[/other]' | first | split: '[#other]' | last %}
              {{ shortcode_description }}
            </div>
          </a>
        {% endif %}
      </div>
    {% endif %}

1 Ответ

0 голосов
/ 17 мая 2019

Вы можете создать фрагмент, например, под названием shortcode.liquid

В фрагменте вы вставили следующий код:

{%- capture open_tag -%}[#{{tag}}]{%- endcapture -%}
{%- capture close_tag -%}[/{{tag}}]{%- endcapture -%}

{%- assign text_content = content | split: open_tag | last | split: close_tag | first -%}
{%- capture remove_shortcode -%}{{open_tag}}{{text_content}}{{close_tag}}{%- endcapture -%}

{%- assign new_content = content | remove: remove_shortcode -%}

И вы называете этот фрагмент так:

{%- include 'shortcode' content: product.content, tag: 'size' -%}

Куда вы передаете контент (в данном случае это product.content ) и шорткод, на который вы хотите настроить таргетинг (в данном случае это размер )

После вызова фрагмента у вас есть две переменные:

{{text_content}} это вернет содержимое между шорткодами

{{new_content}} - это вернет новый контент, но с удаленным шорткодом

Внимание! Этот фрагмент будет работать только для одного экземпляра одного и того же шорткода, a.k.a У вас не может быть двух экземпляров size шорткода.

...