Shopify Liquid Array Filters की पूरी Guideline हिंदी में!

shopify liquid array filters in hindi

Introduction

हेलो दोस्तों आज हम इस post में Shopify Liquid Array Filters के बारे में जानगे!. As Shopify Developers के लिए Liquid एक बहुत ही Important template language है और Liquid की मदद से हम अपने Shopify store के data को manipulate और display कर सकते है। Liquid में कई प्रकार के Filters available है, जिनका इस्तेमाल string,numbers और arrays पर किया जाता है। इस article में हम खासतौर पर Shopify Liquid में Array filters को example के समझेंगे!.

What are Shopify Liquid Array Filters?

Shopify liquid code में जब भी किसी list या array जैसे की products, tags, collections के data को modify या filter करना हो, तब हम array filter का इस्तेमाल करते है!.Shopify in Array filter से आप array के data को sort, join, reverse, unique जैसे filter perform या apply कर सकते है!.

Shopify Liquid Array Filters list with description and example

compact

इस filter का उपयोग array से nil (empty) items को हटाने के लिए किया जाता है।

Example:

{% assign my_array = "apple,,banana,," | split: "," %}
{{ my_array | compact | join: ", " }}

ऊपर के example में देख सकते है की हमारे पास 4-index value है! जिसमे दो index value empty है तो वह उस empty index वाले items को remove करके “apple,banana” दो item return करता है!

concat

इस filter का उपयोग दो arrays को जोड़ने (concatenate/combine) के लिए किया जाता है।

Example:

{% assign tags = product.tags %}
{% assign collection_titles = collection.products | map: "title" %}
{{ tags | concat: collection_titles | join: ", " }}

ऊपर के Example में देख सकते है Product के tags + Collection के सभी product titles एक list में।

find

यह filter array से पहला item लौटाता है जिसकी property value match करती हो।

Example:

{% assign found_product = collection.products | find: "title", "T-Shirt" %}
{{ found_product.title }}

Example में Collection में पहला product जिसका title “T-Shirt” है। वह return करता है!

find_index

यह filter array से उस item का index return करता है जिसकी property value match करती हो।

Example:

{{ collection.products | map: "title" | find_index: "Shoes" }}

Example में देख सकते है अगर “Shoes” तीसरा product है, तो result होगा 2।

first

यह filter array से पहला item लौटाने के लिए उपयोग होता है।

Example:

{% assign first_product = collection.products | first %}
{{ first_product.title }}

Example में देख सकते है Collection का पहला product return करता है!

has

यह filter check करने के लिए कि array में कोई specific property value मौजूद है या नहीं।

Example:

{% if product.tags | has: "summer" %}
  This product has the summer tag
{% endif %}

Example में देख सकते है अगर product के पास summer tag है तो message print होगा।

join

यह filter array के सभी items को एक single string में जोड़ देता है (separator specify कर सकते हैं)।

Example:

{{ product.tags | join: " | " }}
Output: cotton | summer | men
last

यह filter array से last item return करने के लिए उपयोग होता है।

Example:

{% assign last_product = collection.products | last %}
{{ last_product.title }}

Example में देख सकते है की वह Collection का आखिरी product return करेंगा!।

map

यह filter array से किसी specific property values की नई list (array) बनाता है।

Example:

{{ collection.products | map: "vendor" | join: ", " }}

Example में देख सकते है वह Collection में सभी product vendors की list provide करता है!

reject

यह filter array से specific property value वाले items को exclude करने के लिए उपयोग किया जाता है।

Example:

{% assign other_products = collection.products | reject: "vendor", "Nike" %}
{% for product in other_products %}
  {{ product.vendor }} - {{ product.title }}<br>
{% endfor %}

Collection के सभी products except “Nike”।

reverse

यह filter array के items का order उल्टा (reverse) कर देता है।

Example:

{% assign reversed_products = collection.products | reverse %}
{% for product in reversed_products %}
  {{ product.title }}<br>
{% endfor %}

वह Collection products reverse order में दिखायेगा!

size

यह filter array या string की length (size) लौटाता है।

Example:

{{ collection.products | size }}

Example में देख सकते है वह collection के सभी products का total count return करेगा!

sort

यह filter array के items को case-sensitive alphabetical या numerical order में sort करता है।

Example:

{% assign sorted_titles = collection.products | map: "title" | sort %}
{{ sorted_titles | join: ", " }}

Example में देख सकते है वह Product titles alphabetical order में दिखायेगा!

sort_natural

यह filter array के items को case-insensitive natural alphabetical order में sort करता है।

Example:

{% assign sorted_titles = collection.products | map: "title" | sort_natural %}
{{ sorted_titles | join: ", " }}
sum

यह filter array के सभी numeric elements का sum लौटाता है।

Example:

{{ collection.products | map: "price" | sum }}

वह Collection में सभी products की total price दिखायेगा!

uniq

यह filter array से duplicate items हटाकर unique values लौटाता है।

Example:

{{ product.tags | uniq | join: ", " }}

Duplicate tags हटकर सिर्फ unique tags दिखेंगे।

where

यह filter array से केवल वही items लौटाता है जिनकी property value match करती है।

Example:

{% assign nike_products = collection.products | where: "vendor", "Nike" %}
{% for product in nike_products %}
  {{ product.title }}<br>
{% endfor %}

Collection के केवल “Nike” brand वाले products ही दिखायेगा!

Leave a Comment

Your email address will not be published. Required fields are marked *