Please Help

Highlighted
New Member
5 0 0

Hi, I am relatively new to coding and am messing around with the code to change the unit on the product card is based off the product tag. I am guiding myself throught another tutorial of something simmilar. 

 

  <noscript>
    {% capture image_size %}{{ max_height }}x{{ max_height }}{% endcapture %}
    <img class="grid-view-item__image" src="{{ preview_image | img_url: image_size, scale: 2 }}" alt="{{ preview_image.alt }}" style="max-width: {{ max_height | times: preview_image.aspect_ratio }}px;">
  </noscript>

  <div class="h4 grid-view-item__title product-card__title" aria-hidden="true">{{ product.title }}</div>

  {% include 'product-price-listing',{% if product.tags contains "Verdura" %} 
  "Precio Por Unidad."
  {% elsif product.tags contains "Fruta"%}
  "Precio por Pieza"
  {% endif %}
  %

 

this is my code and i dont know why i am getting the error:

Line 50 — Liquid syntax error: Unknown tag 'Elsif'

line 50 being the  " {% elsif product.tags contains "Fruta"%}

 

0 Likes
Highlighted
Shopify Partner
2413 525 671

Hey @AJAKA-Bolivia,

Please replace this code

{% include 'product-price-listing',{% if product.tags contains "Verdura" %} 
  "Precio Por Unidad."
  {% elsif product.tags contains "Fruta"%}
  "Precio por Pieza"
  {% endif %}

with the following

{% if product.tags contains "Verdura" %}
  {% assign my_tag1 = "Precio Por Unidad" %}
{% elsif product.tags contains "Fruta" %}
    {% assign my_tag1 = "Precio por Pieza" %}
 {% endif %}

{% include 'product-price-listing', my_tag %}

 

Hope this works!

If helpful then please Like and Accept Solution.
Do you need custom changes on store ? Hire me.
Feel free to Contact me on dmw.webartisan@gmail.com
Follow us on Instagram @dmw.webartisan
0 Likes
Highlighted
New Member
5 0 0

Hi @dmwwebartisan!

Thanks for the quick response! 

I have edited the code but it is not showing up on the collections page for some reason. 

Here is my code on the  product-card-grid.liquid snippet:

 

{% comment %}
    Renders a product card using "Grid" style
    Accepts:
    - max_height: {Number} Maximum height of the product's image (required)
    - product: {Object} Product Liquid object (required)
    - show_vendor: {Boolean} Show the product's vendor depending on the section setting (optional)

    Usage:
    {% include 'product-card-grid', max_height: max_height, product: product, show_vendor: section.settings.show_vendor %}
{% endcomment %}
<div class="grid-view-item{% unless product.available %} grid-view-item--sold-out{% endunless %} product-card">
  <a class="grid-view-item__link grid-view-item__image-container full-width-link" href="{{ product.url | within: collection }}">
    <span class="visually-hidden">{{ product.title }}</span>
  </a>

  {% capture img_id %}ProductCardImage-{{ section.id }}-{{ product.id }}{% endcapture %}
  {% capture wrapper_id %}ProductCardImageWrapper-{{ section.id }}-{{ product.id }}{% endcapture %}
  {%- assign preview_image = product.featured_media.preview_image -%}
  {%- assign img_url = preview_image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' -%}

  {% unless preview_image == blank %}
    {% include 'image-style', image: preview_image, height: max_height, wrapper_id: wrapper_id, img_id: img_id %}
  {% endunless %}

  <div class="product-card__image-with-placeholder-wrapper" data-image-with-placeholder-wrapper>
    <div id="{{ wrapper_id }}" class="grid-view-item__image-wrapper product-card__image-wrapper js">
      <div style="padding-top:{% unless preview_image == blank %}{{ 1 | divided_by: preview_image.aspect_ratio | times: 100 }}%{% else %}100%{% endunless %};">
        <img id="{{ img_id }}"
              class="grid-view-item__image lazyload"
              alt="{{ preview_image.alt }}"
              data-src="{{ img_url }}"
              data-widths="[180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 2048]"
              data-aspectratio="{{ preview_image.aspect_ratio }}"
              data-sizes="auto"
              data-image>
      </div>
    </div>
    <div class="placeholder-background placeholder-background--animation" data-image-placeholder></div>
  </div>

  <noscript>
    {% capture image_size %}{{ max_height }}x{{ max_height }}{% endcapture %}
    <img class="grid-view-item__image" src="{{ preview_image | img_url: image_size, scale: 2 }}" alt="{{ preview_image.alt }}" style="max-width: {{ max_height | times: preview_image.aspect_ratio }}px;">
  </noscript>

  <div class="h4 grid-view-item__title product-card__title" aria-hidden="true">{{ product.title }}</div>

 {% if product.tags contains "Verdura" %}
  {% assign my_tag1 = "Precio Por Unidad" %}
{% elsif product.tags contains "Pollo" %}
    {% assign my_tag1 = "Precio por Kilo" %}
 {% endif %}

{% include 'product-price-listing', my_tag1 %}

  
</div>
<form method="post" action="/cart/add">
  			<input type="hidden" name="id" value="{{ product.variants.first.id }}" />
 		 	<input min="1" type="number" id="quantity" name="quantity" value="1"/>
  			<input type="submit" value="Añadir al carrito" class="btn" />
			</form> 

 

0 Likes
Highlighted
Shopify Partner
2413 525 671

Hey @AJAKA-Bolivia,

Hmm. Try to print my_tag1 variable somewhere like {{my_tag1}}

See what value comes out with that.

 

Cheers!

If helpful then please Like and Accept Solution.
Do you need custom changes on store ? Hire me.
Feel free to Contact me on dmw.webartisan@gmail.com
Follow us on Instagram @dmw.webartisan
0 Likes
Highlighted
New Member
5 0 0

Hi @dmwwebartisan 

Still no luck  

im trying to maybe implement it into the product price listing and modify that code since I know that that shows up 

{% comment %}
    Renders a list of product's price (regular, sale, unit)
    Accompanies product listings (collection page, search result) and not updated dynamically
    Accepts:
    - variant: {Object} Variant Liquid object (optional)
    - product: {Object} Product Liquid object (optional)
    - show_vendor: {Boolean} Show the product's vendor depending on the section setting (optional)

    Usage:
    {% include 'product-price-listing', product: product %}
{% endcomment %}
{%- liquid
  if product.title
    assign compare_at_price = product.compare_at_price
    assign price = product.price
    assign available = product.available
    assign variant = product.variants.first
  else
    assign compare_at_price = 1999
    assign price = 1999
    assign available = true
  endif

  assign money_price = price | money
-%}

<dl class="price price--listing
  {%- if available == false %} price--sold-out {% endif -%}
  {%- if compare_at_price > price %} price--on-sale {% endif -%}
  {%- if product.price_varies == false and product.compare_at_price_varies %} price--compare-price-hidden {% endif -%}
  {%- if variant.unit_price_measurement %} price--unit-available {% endif -%}"
>
  {% if show_vendor and product %}
    <div class="price__vendor price__vendor--listing">
      <dt>
        <span class="visually-hidden">{{ 'products.product.vendor' | t }}</span>
      </dt>
      <dd>
        {{ product.vendor }}
      </dd>
    </div>
  {% endif %}

  {%- comment -%}
    Explanation of description list:
      - div.price__regular: Displayed when there are no variants on sale
      - div.price__sale: Displayed when a variant is a sale
      - div.price__unit: Displayed when the first variant has a unit price
      - div.price__availability: Displayed when the product is sold out
  {%- endcomment -%}
  <div class="price__regular">
    <dt>
      <span class="visually-hidden visually-hidden--inline">{{ 'products.product.regular_price' | t }}</span>
    </dt>
    <dd>
      <span class="price-item price-item--regular">
        {%- if product.price_varies -%}
          {{ 'products.product.from_lowest_price_html' | t: lowest_price: money_price }}
        {%- else -%}
          {{ money_price }}
        {%- endif -%}
      </span>
    </dd>
  </div>
  <div class="price__sale">
    <dt>
      <span class="visually-hidden visually-hidden--inline">{{ 'products.product.sale_price' | t }}</span>
    </dt>
    <dd>
      <span class="price-item price-item--sale">
        {%- if product.price_varies -%}
          {{ 'products.product.from_lowest_price_html' | t: lowest_price: money_price }}
        {%- else -%}
          {{ money_price }}
        {%- endif -%}
      </span>
    </dd>
    <div class="price__compare">
      <dt>
        <span class="visually-hidden visually-hidden--inline">{{ 'products.product.regular_price' | t }}</span>
      </dt>
      <dd>
        <s class="price-item price-item--regular">
          {{ compare_at_price | money }}
        </s>
      </dd>
    </div>
  </div>
  <div class="price__unit">
    <dt>
      <span class="visually-hidden visually-hidden--inline">{{ 'products.product.unit_price_label' | t }}</span>
    </dt>
    <dd class="price-unit-price">
      {%- capture unit_price_separator -%}
        <span aria-hidden="true">/</span><span class="visually-hidden">{{ 'general.accessibility.unit_price_separator' | t }}&nbsp;</span>
      {%- endcapture -%}
      {%- capture unit_price_base_unit -%}
        <span>
          {%- if variant.unit_price_measurement -%}
            {%- if variant.unit_price_measurement.reference_value != 1 -%}
              {{- variant.unit_price_measurement.reference_value -}}
            {%- endif -%}
            {{ variant.unit_price_measurement.reference_unit }}
          {%- endif -%}
        </span>
      {%- endcapture -%}
	
      {% if product.tags contains "Verdura" %}
    {% assign my_tag1 = "Precio Por Unidad" %}
	{% elsif product.tags contains "Pollo" %}
    {% assign my_tag1 = "Precio por Kilo" %}
    {% endif %}
      <span>{{ variant.unit_price | money }}</span>{{- unit_price_separator -}}{{- unit_price_base_unit -}} {{ my_tag1 }}
    </dd>
  </div>
  <div class="price__badges price__badges--listing">
    <span class="price__badge price__badge--sale" aria-hidden="true">
      <span>{{ 'products.product.on_sale' | t }}</span>
    </span>
    <span class="price__badge price__badge--sold-out">
      <span>{{ 'products.product.sold_out' | t }}</span>
    </span>
  </div>
</dl>
0 Likes