Showing posts with label Liquid. Show all posts
Showing posts with label Liquid. Show all posts

Thursday 20 July 2023

How to get Parameter in Shopify liquid

 {% assign month = '01' %}

{% assign day = '01' %}


{%- assign page_url = content_for_header | split:'"pageurl":"' | last | split:'"' | first | split: request.host | last | replace:'\/','/' | replace:'%20',' ' | replace:'\u0026','&'  -%}

{%- assign param = blank -%}


{%- for i in (1..1) -%}


  {%- unless page_url contains "?" -%}{% break %}{%- endunless -%}

  {%- assign query_string = page_url | split:'?' | last -%}

  {%- assign qry_parts= query_string | split:'&' -%}


  {%- for part in qry_parts -%}

    {%- assign key_and_value = part | split:'=' -%}

    {%- if key_and_value.size > 1 -%}

      

      {%- if key_and_value[0] == 'birth_month' -%}

        {%- assign month = key_and_value[1] -%}

      {%- endif -%}

       {%- if key_and_value[0] == 'birth_day' -%}

        {%- assign day = key_and_value[1] -%}

      {%- endif -%}

    {%- endif -%}

  {%- endfor -%}

{%- endfor -%}

<form method="GET" action="/pages/find-your-zodiac-sign">

  <label for="birth_month">Birth Month:</label>

  <input type="number" value="{{ month }}" id="birth_month" name="birth_month" min="1" max="12" required>

  <br>

  <label for="birth_day">Birth Day:</label>

  <input type="number" value="{{ day }}" id="birth_day" name="birth_day" min="1" max="31" required>

  <br>

  {%- assign min = 1 -%}

  {%- assign max = 10000 -%}

  {%- assign diff = max | minus: min -%}

  {%- assign random_number = "now" | date: "%N" | modulo: diff | plus: min -%}

  <input type="hidden" value="{{ random_number }}" name="type">

  <button type="submit">Find Zodiac Sign</button>

</form>

{% assign month = month | times: 1 %}

{% assign day = day | times: 1 %}

{{month }}

{{day }}

Saturday 31 October 2020

How to create simple dynamic section with block in Shopify liquid in theme

add {% section 'contactpagefaq' %} on your template file

Create new section file called : contactpagefaq.liquid, and paste following code.

{% if section.settings.faqenable %}
<h2>{{ section.settings.faqtitle }}</h2>   

  {% for block in section.blocks %}  
  
  <button class="accordion">{{ block.settings.sectiontitle }}</button>
          <div class="panel">
            <p>{{ block.settings.sectiontext }}</p>
          </div>
  {% endfor %}
{% endif %}
{% schema %}
{
  "name": "Contact Page FAQ",
  "max_blocks": 5,
  "settings": [
{
          "id": "faqenable",
          "type": "checkbox",
          "label": "Enable",
          "default": true
        },
        {
          "id": "faqtitle",
          "type": "text",
          "label": "Heading",
          "default": "FAQ"
        }
      ],
  "blocks": [
    {
      "type": "select",
      "name": "Block",
      "settings": [
{
          "id": "sectiontitle",
          "type": "text",
          "label": "Title"
        },
        {
          "id": "sectiontext",
          "type": "textarea",
          "label": "Text"
        }
      ]
    }
  ]
}
{% endschema %}

{% stylesheet %}
{% endstylesheet %}

{% javascript %}
{% endjavascript %}

Saturday 29 June 2019

How to change startSymbol endSymbol of Angular JS

I face the issue when use Angular JS in shopify liquid file at that time I have use following script.

var fetch = angular.module('myapp', []).config(function ($interpolateProvider) {
    $interpolateProvider.startSymbol('{[{').endSymbol('}]}');
});

Monday 24 June 2019

How to concat string and variable in Liquid Shopify in PHP with proxy URL

<script type="text/javascript">
{% if customer  %}
    {% assign customerid = '"<?php echo base_url('checkout?id='.$postdata['cart_id']); ?>' | append: '&customer=' | append: customer.id | append: '"' %}
{% else %}
    {% assign customerid = '"<?php echo base_url('checkout?id='.$postdata['cart_id']); ?>' | append: '"' %}
{% endif %}
var checkouturl = {{customerid}};
window.location.replace(checkouturl);
</script>