الفرق بين المراجعتين ل"Liquid/filters"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
 
(7 مراجعات متوسطة بواسطة مستخدمين اثنين آخرين غير معروضة)
سطر 1: سطر 1:
== المرشّحات Filters ==
+
<noinclude>{{DISPLAYTITLE:المرشحات Filters في Liquid}}</noinclude>
 +
تعرض هذه الصفحة كل المرشحات الموجودة في Liquid مع أمثلة على كل واحدة منها وذكر كل التفاصيل المتعلقة بها، يمكنك استعمال الفهرس للانتقال للمرشح المطلوب مباشرةً.
  
=== abs ===
+
== <code>abs</code> ==
يعيد هذا المرشّح قيمة عدد المطلقة.
+
يعيد هذا المرشّح قيمة العدد المطلقة.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
|+
 
!الدخل
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ -17 | abs }}
 
{{ -17 | abs }}
 
{{ 4 | abs }}
 
{{ 4 | abs }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|}
+
17
{| class="wikitable"
+
4
!الخرج
+
</syntaxhighlight>يعمل المرشّح <code>abs</code> أيضًا مع سلسلة نصية تحتوي على عدد فقط.<syntaxhighlight lang="liquid">
|-
 
|<code>17</code>
 
 
 
<code>4</code>
 
|}
 
يعمل المرشّح <code>abs</code> أيضًا مع سلسلة نصية تحتوي على عدد فقط.
 
{| class="wikitable"
 
!الدخل
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "-19.86" | abs }}
 
{{ "-19.86" | abs }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
19.86
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
+
== <code>append</code> ==
{| class="wikitable"
+
يضيف هذا المرشّح سلسلة نصية محدَّدة إلى نهاية سلسلة نصية أخرى.<syntaxhighlight lang="liquid">
!الخرج
 
|-
 
|<code>19.86</code>
 
|}
 
 
 
=== append ===
 
يضيف هذا المرشّح السلسلة النصية المحددة إلى نهاية سلسلة نصية أخرى.
 
{| class="wikitable"
 
!الدخل
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "/my/fancy/url" | append: ".html" }}
 
{{ "/my/fancy/url" | append: ".html" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|}
+
/my/fancy/url.html
{| class="wikitable"
+
</syntaxhighlight>يمكن للمرشّح <code>append</code> أيضًا قبول متغير كوسيطٍ له.<syntaxhighlight lang="liquid">
!الخرج
 
|-
 
|‎<code>/my/fancy/url.html</code>
 
|}
 
يمكن للمرشّح <code>append</code> أيضًا قبول متغير كوسيطٍ له.
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign filename = "/index.html" %}
 
{% assign filename = "/index.html" %}
 
{{ "website.com" | append: filename }}
 
{{ "website.com" | append: filename }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
website.com/index.html
 
</syntaxhighlight>
 
</syntaxhighlight>
| <code>website.com/index.html</code>
 
|}
 
  
=== at_least (خاص بالإصدار 4.0.1) ===
+
== <code>at_least</code> (خاص بالإصدار 4.0.1) ==
يَحُدّ من عددٍ ما إلى حد القيمة الأدنى.
+
يحدّد قيمة عددٍ ما بالقيمة الدنيا.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 4 | at_least: 5 }}
 
{{ 4 | at_least: 5 }}
 
{{ 4 | at_least: 3 }}
 
{{ 4 | at_least: 3 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
5
 +
4
 
</syntaxhighlight>
 
</syntaxhighlight>
|<code>5</code>
 
<code>4</code>
 
|}
 
  
=== at_most (خاص بالإصدار 4.0.1) ===
+
== <code>at_most</code> (خاص بالإصدار 4.0.1) ==
يَحُدّ من عددٍ ما إلى حد القيمة الأعلى.
+
يحدّد قيمة عددٍ ما بالقيمة العليا.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 4 | at_most: 5 }}
 
{{ 4 | at_most: 5 }}
 
{{ 4 | at_most: 3 }}
 
{{ 4 | at_most: 3 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
4
 +
3
 
</syntaxhighlight>
 
</syntaxhighlight>
|<code>4</code>
 
<code>3</code>
 
|}
 
  
=== capitalize ===
+
== <code>capitalize</code> ==
يجعل هذا المرشّح الحرف الأول من سلسلة نصية حرفًا كبيرًا ويحوّل الأحرف المتبقية إلى أحرف صغيرة.
+
يجعل هذا المرشّح الحرف الأول من سلسلة نصية باللغة الإنجليزية حرفًا كبيرًا ويحوّل الأحرف المتبقية إلى أحرف صغيرة.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "title" | capitalize }}
 
{{ "title" | capitalize }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<code>Title</code>
+
Title
|}
+
</syntaxhighlight>يُكتَب الحرف الأول فقط من سلسلة نصية إنجليزية كحرف كبير، لذلك لا تُكتَب الأحرف الأولى من الكلمات اللاحقة بأحرف كبيرة:<syntaxhighlight lang="liquid">
يُكتَب الحرف الأول فقط من السلسلة النصية كحرف كبير، لذلك لا تُكتَب الأحرف الأولى من الكلمات اللاحقة بأحرف كبيرة:
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "my GREAT title" | capitalize }}
 
{{ "my GREAT title" | capitalize }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
My great title
 
</syntaxhighlight>
 
</syntaxhighlight>
|<code>My great title</code>
 
|}
 
  
=== ceil ===
+
== <code>ceil</code> ==
يقرّب هذا المرشّح الدخل إلى أقرب عدد صحيح. تحاول لغة Liquid تحويل الدخل إلى عدد قبل تطبيق المرشّح.
+
يقرّب هذا المرشّح الدخل إلى أقرب وأكبر عدد صحيح، إذ تحاول لغة Liquid تحويل الدخل إلى عدد قبل تطبيق المرشّح.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 1.2 | ceil }}
 
{{ 1.2 | ceil }}
 
{{ 2.0 | ceil }}
 
{{ 2.0 | ceil }}
 
{{ 183.357 | ceil }}
 
{{ 183.357 | ceil }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<code>2</code>
+
2
<code>2</code>
+
2
 
+
184
<code>184</code>
+
</syntaxhighlight>سنستخدم في المثال التالي قيمة الدخل على أنها سلسلة نصية:<syntaxhighlight lang="liquid">
|}
 
سنستخدم في المثال التالي قيمة الدخل كسلسلة نصية:
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "3.5" | ceil }}
 
{{ "3.5" | ceil }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
4
 
</syntaxhighlight>
 
</syntaxhighlight>
|<code>4</code>
 
|}
 
  
=== compact (خاص بالإصدار 4.0.0) ===
+
== <code>compact</code> (خاص بالإصدار 4.0.0) ==
 
يزيل هذا المرشّح أي قيم <code>nil</code> من المصفوفة.
 
يزيل هذا المرشّح أي قيم <code>nil</code> من المصفوفة.
  
افترض في المثال التالي أن <code>site.pages</code> عبارة عن مجموعة من صفحات محتوى موقع ويب، وبعض هذه الصفحات لها سِمة تسمى <code>category</code> تحدّد فئة محتوى الصفحة. إذا ربطنا <code>map</code> هذه الفئات مع مصفوفة، فقد تكون بعض قيم عناصر المصفوفة <code>nil</code> إن لم تتضمن صفحةٌ ما السمة <code>category</code>.
+
افترض في المثال التالي أن <code>site.pages</code> عبارة عن مجموعة من صفحات محتوى موقع ويب، وبعض هذه الصفحات لها سِمة attribute تسمى <code>category</code> تحدّد فئة محتوى الصفحة. إذا ربطنا هذه الفئات مع مصفوفة عبر <code>map</code>، فقد تكون بعض قيم عناصر المصفوفة <code>nil</code> إن لم تتضمن صفحةٌ ما السمة <code>category</code>.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign site_categories = site.pages | map: "category" %}
 
{% assign site_categories = site.pages | map: "category" %}
  
سطر 150: سطر 80:
 
- {{ category }}
 
- {{ category }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
- business
 
- business
 
- celebrities
 
- celebrities
سطر 159: سطر 88:
 
-
 
-
 
- technology
 
- technology
</syntaxhighlight>
+
</syntaxhighlight>لكن يمكننا إزالة جميع قيم <code>nil</code> في المصفوفة باستخدام المرشّح <code>compact</code> عند إنشاء المصفوفة <code>site_categories</code>.<syntaxhighlight lang="liquid">
|}
 
لكن يمكننا إزالة جميع قيم <code>nil</code> في المصفوفة باستخدام المرشّح <code>compact</code> عند إنشاء المصفوفة <code>site_categories</code>.
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign site_categories = site.pages | map: "category" | compact %}
 
{% assign site_categories = site.pages | map: "category" | compact %}
  
سطر 172: سطر 94:
 
- {{ category }}
 
- {{ category }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
- business
 
- business
 
- celebrities
 
- celebrities
سطر 180: سطر 101:
 
- technology
 
- technology
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
=== concat (خاص بالإصدار 4.0.0) ===
+
== <code>concat</code> (خاص بالإصدار 4.0.0) ==
يربط (يضم معًا) مصفوفات متعددة، إذ تحتوي المصفوفة الناتجة على جميع العناصر من مصفوفات الدخل.
+
يربط هذا المرشّح (أو يضم معًا) مصفوفات متعددة، إذ تحتوي المصفوفة الناتجة على جميع العناصر من مصفوفات الدخل.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign fruits = "apples, oranges, peaches" | split: ", " %}
 
{% assign fruits = "apples, oranges, peaches" | split: ", " %}
 
{% assign vegetables = "carrots, turnips, potatoes" | split: ", " %}
 
{% assign vegetables = "carrots, turnips, potatoes" | split: ", " %}
سطر 197: سطر 112:
 
- {{ item }}
 
- {{ item }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
- apples
 
- apples
 
- oranges
 
- oranges
سطر 205: سطر 119:
 
- turnips
 
- turnips
 
- potatoes
 
- potatoes
</syntaxhighlight>
+
</syntaxhighlight>يمكنك تجميع مرشّحات <code>concat</code> متعددة معًا لضم أكثر من مصفوفتين.<syntaxhighlight lang="liquid">
|}
 
يمكنك تجميع مرشّحات <code>concat</code> متعددة معًا لضم أكثر من مصفوفتين.
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign furniture = "chairs, tables, shelves" | split: ", " %}
 
{% assign furniture = "chairs, tables, shelves" | split: ", " %}
  
سطر 220: سطر 127:
 
- {{ item }}
 
- {{ item }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
- apples
 
- apples
 
- oranges
 
- oranges
سطر 232: سطر 138:
 
- shelves
 
- shelves
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
=== date ===
+
== <code>date</code> ==
يحوّل هذا المرشّح العلامة الزمنية timestamp إلى تنسيق تاريخ date آخر، فتنسيق هذه الصيغة هو <code>[http://strftime.net/ strftime]</code> نفسه. يستخدم الدخل تنسيق <code>[https://ruby-doc.org/stdlib-3.0.2/libdoc/time/rdoc/Time.html#method-c-parse Time.parse]</code> الخاص بلغة روبي Ruby نفسه.
+
يحوّل هذا المرشّح علامة زمنية timestamp إلى تنسيق تاريخ date آخر، فتنسيق هذه الصيغة هو <code>[http://strftime.net/ strftime]</code> نفسه، بينما يستخدم الدخل تنسيق <code>[https://ruby-doc.org/stdlib-3.0.2/libdoc/time/rdoc/Time.html#method-c-parse Time.parse]</code> الخاص بلغة [[Ruby|روبي]] [[Ruby]] نفسه.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ article.published_at | date: "%a, %b %d, %y" }}
 
{{ article.published_at | date: "%a, %b %d, %y" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
Fri, Jul 17, 15
 
Fri, Jul 17, 15
</syntaxhighlight>
+
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
|}
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ article.published_at | date: "%Y" }}
 
{{ article.published_at | date: "%Y" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
2015
 
2015
</syntaxhighlight>
+
</syntaxhighlight>يعمل المرشّح <code>date</code> مع السلاسل النصية إذا احتوت على تواريخ جيدة التنسيق.<syntaxhighlight lang="liquid">
|}
 
يعمل المرشّح <code>date</code> مع السلاسل النصية إذا احتوت على تواريخ جيدة التنسيق.
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "March 14, 2016" | date: "%b %d, %y" }}
 
{{ "March 14, 2016" | date: "%b %d, %y" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
Mar 14, 16
 
Mar 14, 16
</syntaxhighlight>
+
</syntaxhighlight>يمكنك الحصول على الوقت الحالي من خلال تمرير الكلمة الخاصة <code>"now"</code> (أو <code>"today"</code>) إلى المرشّح <code>date</code>.<syntaxhighlight lang="liquid">
|}
 
يمكنك الحصول على الوقت الحالي من خلال تمرير الكلمة الخاصة <code>"now"</code> (أو <code>"today"</code>) إلى المرشّح <code>date</code>.
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}.
 
This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}.
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
This page was last updated at 2021-04-28 17:52.
 
This page was last updated at 2021-04-28 17:52.
</syntaxhighlight>
+
</syntaxhighlight>لاحظ أن القيمة ستكون هي الوقت الحالي لآخر إنشاء للصفحة من القالب، وليس وقت تقديم الصفحة إلى المستخدم في حالة التخزين المؤقت أو إنشاء موقع ساكن.
|}
 
لاحظ أن القيمة ستكون هي الوقت الحالي لآخر إنشاء للصفحة من القالب، وليس وقت تقديم الصفحة إلى المستخدم في حالة التخزين المؤقت أو إنشاء موقع ساكن.
 
  
=== default ===
+
== <code>default</code> ==
يضبط قيمة افتراضية للمتغير الذي لا يملك قيمة مُسنَدة. سيظهر المرشّح <code>default</code> قيمته إذا كان الدخل <code>nil</code> أو <code>false</code> أو فارغ.
+
يضبط قيمة افتراضية للمتغير الذي لا يملك قيمة مُسنَدة. سيظهِر المرشّح <code>default</code> قيمته إذا كان الدخل قيمة <code>nil</code> أو <code>false</code> أو قيمة فارغة.
  
لم تُحدَّد قيمة المتغير <code>product_price</code>، لذلك اُستخدِمت القيمة الافتراضية في المثال التالي:
+
لم تُحدَّد قيمة المتغير <code>product_price</code>، لذلك اُستخدِمت القيمة الافتراضية في المثال التالي:<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ product_price | default: 2.99 }}
 
{{ product_price | default: 2.99 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
2.99
 
2.99
</syntaxhighlight>
+
</syntaxhighlight>حُدِّدت قيمة المتغير <code>product_price</code>، لذلك لم تُستخدَم القيمة الافتراضية في المثال التالي:<syntaxhighlight lang="liquid">
|}
 
حُدِّدت قيمة المتغير <code>product_price</code>، لذلك لم تُستخدَم القيمة الافتراضية في المثال التالي:
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign product_price = 4.99 %}
 
{% assign product_price = 4.99 %}
 
{{ product_price | default: 2.99 }}
 
{{ product_price | default: 2.99 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 
  
<code>4.99</code>
+
4.99
|}
+
</syntaxhighlight>قيمة المتغير <code>product_price</code> فارغة، لذلك اُستخدِمت القيمة الافتراضية في المثال التالي:<syntaxhighlight lang="liquid">
قيمة المتغير <code>product_price</code> فارغة، لذلك اُستخدِمت القيمة الافتراضية في المثال التالي:
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign product_price = "" %}
 
{% assign product_price = "" %}
 
{{ product_price | default: 2.99 }}
 
{{ product_price | default: 2.99 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
2.99
 
</syntaxhighlight>
 
</syntaxhighlight>
|
 
  
<code>2.99</code>
+
=== السماح بالقيمة <code>false</code> (خاص بالإصدار 5.0.0) ===
|}
+
يمكن السماح للمتغيرات بأن تعيد القيمة <code>false</code> بدلًا من القيمة الافتراضية من خلال استخدام العامل <code>allow_false</code>.<syntaxhighlight lang="liquid">
 
 
=== بالسماح بالقيمة <code>false</code> (خاص بالإصدار 5.0.0) ===
 
يمكن السماح للمتغيرات أن تعيد القيمة <code>false</code> بدلًا من القيمة الافتراضية من خلال استخدام المعامل <code>allow_false</code>.
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign display_price = false %}
 
{% assign display_price = false %}
 
{{ display_price | default: true, allow_false: true }}
 
{{ display_price | default: true, allow_false: true }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
false
 
</syntaxhighlight>
 
</syntaxhighlight>
|
 
 
<code>false</code>
 
|}
 
  
=== divided_by ===
+
== <code>divided_by</code> ==
 
يقسم هذا المرشّح عددًا على عددٍ آخر.
 
يقسم هذا المرشّح عددًا على عددٍ آخر.
  
تُقرَّب النتيجة إلى أقرب عدد صحيح (كالمرشّح  <code>floor</code>) إذا كان المقسوم عليه عددًا صحيحًا.
+
تُقرَّب النتيجة إلى أقرب وأصغر عدد صحيح (كالمرشّح  <code>floor</code>) إذا كان المقسوم عليه عددًا صحيحًا.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 16 | divided_by: 4 }}
 
{{ 16 | divided_by: 4 }}
 
{{ 5 | divided_by: 3 }}
 
{{ 5 | divided_by: 3 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
4
 
4
 
1
 
1
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
==== التحكم بعملية التقريب ====
+
=== التحكم بعملية التقريب ===
ينتج عن المرشّح <code>divided_by</code> نتيجة من نوع المقسوم عليه نفسه، أي إذا قسمت على عدد صحيح، فستكون النتيجة عددًا صحيحًا. إذا قسمت على عدد عشري float، فستكون النتيجة عددًا عشريًا.
+
ينتج عن المرشّح <code>divided_by</code> نتيجة من نوع المقسوم عليه، أي إذا قسمت على عدد صحيح، فستكون النتيجة عددًا صحيحًا. إذا قسمت على عدد عشري float، فستكون النتيجة عددًا عشريًا.
  
المقسوم عليه في المثال التالي هو عدد صحيح:
+
المقسوم عليه في المثال التالي هو عدد صحيح:<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 20 | divided_by: 7 }}
 
{{ 20 | divided_by: 7 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
2
 
2
</syntaxhighlight>
+
</syntaxhighlight>المقسوم عليه في المثال التالي هو عدد عشري:<syntaxhighlight lang="liquid">
|}
 
المقسوم عليه في المثال التالي هو عدد عشري:
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 20 | divided_by: 7.0 }}
 
{{ 20 | divided_by: 7.0 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
2.857142857142857
 
2.857142857142857
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
==== تغيير أنواع المتغيرات ====
+
=== تغيير أنواع المتغيرات ===
قد ترغب في استخدام متغير كمقسوم عليه، حيث لا يمكنك في هذه الحالة إضافة <code>‎.0</code> لتحويله إلى عدد عشري ببساطة، ولكن يمكنك إسناد <code>assign</code> نسخة محوَّلة من المتغير إلى عدد عشري باستخدام المرشّح <code>times</code>.
+
قد ترغب في استخدام متغير كمقسوم عليه، حيث لا يمكنك في هذه الحالة إضافة <code>‎.0</code> لتحويله إلى عدد عشري ببساطة، ولكن يمكنك إسناد <code>assign</code> نسخة من المتغير محوَّلة إلى عدد عشري باستخدام المرشّح <code>times</code>.
  
سنقسم في المثال التالي على متغير يحتوي على عدد صحيح، لذلك نحصل على عدد صحيح:
+
سنقسم في المثال التالي على متغير يحتوي على عدد صحيح، لذلك سنحصل على عدد صحيح:<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign my_integer = 7 %}
 
{% assign my_integer = 7 %}
 
{{ 20 | divided_by: my_integer }}
 
{{ 20 | divided_by: my_integer }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|
 
  
<code>2</code>
+
2
|}
+
</syntaxhighlight>نضرب المتغير بالعدد <code>1.0</code> باستخدام المرشّح <code>times</code> لنحصل على عدد عشري، ثم نقسم على عدد عشري في المثال التالي:<syntaxhighlight lang="liquid">
نضرب المتغير بالعدد <code>1.0</code> باستخدام المرشّح <code>times</code> لنحصل على عدد عشري، ثم نقسمه على عدد عشري بدلًا من ذلك في المثال التالي:
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign my_integer = 7 %}
 
{% assign my_integer = 7 %}
 
{% assign my_float = my_integer | times: 1.0 %}
 
{% assign my_float = my_integer | times: 1.0 %}
 
{{ 20 | divided_by: my_float }}
 
{{ 20 | divided_by: my_float }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
 +
2.857142857142857
 
</syntaxhighlight>
 
</syntaxhighlight>
|
 
  
<code>2.857142857142857</code>
+
== <code>downcase</code> ==
|}
+
يجعل هذا المرشّح كل حرف في سلسلة نصية بحالة الأحرف الصغيرة، وليس له تأثير على السلاسل النصية التي تتكون من أحرف صغيرة مسبقًا.<syntaxhighlight lang="liquid">
 
 
=== downcase ===
 
يجعل هذا المرشّح كل حرف في سلسلة نصية أحرفًا صغيرة، وليس له تأثير على السلاسل النصية التي تتكون بالفعل من أحرف صغيرة.
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Parker Moore" | downcase }}
 
{{ "Parker Moore" | downcase }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
parker moore
 
parker moore
</syntaxhighlight>
+
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
|}
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "apple" | downcase }}
 
{{ "apple" | downcase }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
apple
 
apple
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
=== escape ===
+
== <code>escape</code> ==
يطبّق هذا المرشّح عملية الهروب على سلسلة نصية عن طريق استبدال المحارف بتسلسلات الهروب escape sequences (بحيث يمكن استخدام هذه السلسلة في عنوان URL مثلًا)، ولا يغيّر السلاسل النصية التي ليس لديها أي شيء لتطبيق عملية الهروب عليه.
+
يطبّق هذا المرشّح عملية الهروب على سلسلة نصية عن طريق استبدال المحارف بتسلسلات الهروب escape sequences (بحيث يمكن استخدام هذه السلسلة في عنوان URL مثلًا)، ولا يغيّر السلاسل النصية التي ليس لديها أي شيء لتطبيق عملية الهروب عليه.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Have you read 'James & the Giant Peach'?" | escape }}
 
{{ "Have you read 'James & the Giant Peach'?" | escape }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
Have you read &#39;James &amp; the Giant Peach&#39;?
 
Have you read &#39;James &amp; the Giant Peach&#39;?
</syntaxhighlight>
+
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
|}
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Tetsuro Takara" | escape }}
 
{{ "Tetsuro Takara" | escape }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
Tetsuro Takara
 
Tetsuro Takara
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
=== escape_once ===
+
== <code>escape_once</code> ==
يطبّق عملية الهروب على سلسلة نصية بدون تغيير الكيانات المُطبَّق عليها الهروب مسبقًا، ولا يغيّر السلاسل النصية التي ليس لديها أي شيء لتطبيق عملية الهروب عليه.
+
يطبّق عملية الهروب على سلسلة نصية بدون تغيير الكيانات المُطبَّق عليها الهروب مسبقًا، ولا يغيّر السلاسل النصية التي ليس لديها أي شيء لتطبيق عملية الهروب عليه.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "1 < 2 & 3" | escape_once }}
 
{{ "1 < 2 & 3" | escape_once }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
1 &lt; 2 &amp; 3
 
1 &lt; 2 &amp; 3
</syntaxhighlight>
+
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
|}
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "1 &lt; 2 &amp; 3" | escape_once }}
 
{{ "1 &lt; 2 &amp; 3" | escape_once }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
1 &lt; 2 &amp; 3
 
1 &lt; 2 &amp; 3
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
=== first ===
+
== <code>first</code> ==
يعيد هذا المرشّح العنصر الأول من المصفوفة.
+
يعيد هذا المرشّح العنصر الأول من مصفوفة.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Ground control to Major Tom." | split: " " | first }}
 
{{ "Ground control to Major Tom." | split: " " | first }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
Ground
 
Ground
</syntaxhighlight>
+
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
|}
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
 
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
  
 
{{ my_array.first }}
 
{{ my_array.first }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
 +
zebra
 
</syntaxhighlight>
 
</syntaxhighlight>
|
+
يمكنك استخدام المرشّح <code>first</code> مع الصيغة النقطية dot notation عندما تحتاج إلى استخدام المرشّح ضمن وسم كما يلي:<syntaxhighlight lang="liquid">
 
 
<code>zebra</code>
 
|}
 
يمكنك استخدام المرشّح <code>first</code> مع الصيغة النقطية عندما تحتاج إلى استخدام المرشّح ضمن وسم:<syntaxhighlight lang="liquid">
 
 
{% if my_array.first == "zebra" %}
 
{% if my_array.first == "zebra" %}
 
   Here comes a zebra!
 
   Here comes a zebra!
سطر 525: سطر 284:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== floor ===
+
== <code>floor</code> ==
يقرّب هذا المرشّح الدخل إلى أقرب عدد صحيح. تحاول لغة Liquid تحويل الدخل إلى عدد قبل تطبيق المرشح.
+
يقرّب هذا المرشّح الدخل إلى أقرب وأصغر عدد صحيح، حيث تحاول لغة Liquid تحويل الدخل إلى عدد قبل تطبيق المرشح.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 1.2 | floor }}
 
{{ 1.2 | floor }}
 
{{ 2.0 | floor }}
 
{{ 2.0 | floor }}
 
{{ 183.357 | floor }}
 
{{ 183.357 | floor }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
1
 
1
 
2
 
2
 
183
 
183
 +
</syntaxhighlight>قيمة الدخل في المثال التالي عبارة عن سلسلة نصية:<syntaxhighlight lang="liquid">
 +
{{ "3.5" | floor }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
3
 +
</syntaxhighlight>
 +
 +
== <code>join</code> ==
 +
يدمج هذا المرشّح العناصر الموجودة في مصفوفة ضمن سلسلة نصية واحدة باستخدام وسيطه كفاصل بينها.<syntaxhighlight lang="liquid">
 +
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
 +
 +
{{ beatles | join: " and " }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
 +
John and Paul and George and Ringo
 +
</syntaxhighlight>
 +
 +
== <code>last</code> ==
 +
يعيد هذا المرشّح العنصر الأخير من مصفوفة.<syntaxhighlight lang="liquid">
 +
{{ "Ground control to Major Tom." | split: " " | last }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Tom.
 +
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
 +
{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}
 +
 +
{{ my_array.last }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
 +
tiger
 +
</syntaxhighlight>
 +
يمكنك استخدام المرشّح <code>last</code> مع الصيغة النقطية عندما تحتاج إلى استخدام هذا المرشّح ضمن وسم كما يلي:<syntaxhighlight lang="liquid">
 +
{% if my_array.last == "tiger" %}
 +
  There goes a tiger!
 +
{% endif %}
 +
</syntaxhighlight>
 +
 +
== <code>lstrip</code> ==
 +
يزيل هذا المرشّح كل المسافات (مسافات tab والمسافات الفارغة والأسطر الجديدة) من جانب السلسلة النصية الأيسر، ولا يؤثر على المسافات بين الكلمات.<syntaxhighlight lang="liquid">
 +
{{ "          So much room for activities          " | lstrip }}!
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
So much room for activities          !
 +
</syntaxhighlight>
 +
 +
== <code>map</code> ==
 +
يُنشئ هذا المرشّح مصفوفة من القيم عن طريق استخراج قيم خاصيةٍ مسمَّاة من كائن آخر.
 +
 +
افترض في المثال التالي أن الكائن <code>site.pages</code> يحتوي على جميع البيانات الوصفية metadata لموقع ويب. يؤدي استخدام الوسم <code>assign</code> مع المرشّح <code>map</code> إلى إنشاء متغير يحتوي فقط على قيم خصائص الفئة <code>category</code> لكل شيء في الكائن <code>site.pages</code>.<syntaxhighlight lang="liquid">
 +
{% assign all_categories = site.pages | map: "category" %}
 +
 +
{% for item in all_categories %}
 +
- {{ item }}
 +
{% endfor %}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
- business
 +
- celebrities
 +
- lifestyle
 +
- sports
 +
- technology
 +
</syntaxhighlight>
 +
 +
== <code>minus</code> ==
 +
يطرح عددًا من عدد آخر.<syntaxhighlight lang="liquid">
 +
{{ 4 | minus: 2 }}
 +
{{ 16 | minus: 4 }}
 +
{{ 183.357 | minus: 12 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
2
 +
12
 +
171.357
 +
</syntaxhighlight>
 +
 +
== <code>modulo</code> ==
 +
يعيد هذا المرشّح الباقي من عملية قسمة.<syntaxhighlight lang="liquid">
 +
{{ 3 | modulo: 2 }}
 +
{{ 24 | modulo: 7 }}
 +
{{ 183.357 | modulo: 12 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
1
 +
3
 +
3.357
 +
</syntaxhighlight>
 +
 +
== <code>newline_to_br</code> ==
 +
يدخل هذا المرشّح الفاصل السطري (<code><nowiki><br /‎></nowiki></code>) الخاص بلغة HTML أمام كل سطر جديد (<code>‎\n</code>) في سلسلة نصية.<syntaxhighlight lang="liquid">
 +
{% capture string_with_newlines %}
 +
Hello
 +
there
 +
{% endcapture %}
 +
 +
{{ string_with_newlines | newline_to_br }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
 +
<br />
 +
Hello<br />
 +
there<br />
 +
</syntaxhighlight>
 +
 +
== <code>plus</code> ==
 +
يجمع هذا المرشّح عددين.<syntaxhighlight lang="liquid">
 +
{{ 4 | plus: 2 }}
 +
{{ 16 | plus: 4 }}
 +
{{ 183.357 | plus: 12 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
6
 +
20
 +
195.357
 +
</syntaxhighlight>
 +
 +
== <code>prepend</code> ==
 +
يضيف هذا المرشّح سلسلة نصية محدَّدة إلى بداية سلسلة نصية أخرى.<syntaxhighlight lang="liquid">
 +
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Some fruit: apples, oranges, and bananas
 +
</syntaxhighlight>يمكن أن يقبل المرشّح <code>prepend</code> أيضًا متغيرًا كوسيطٍ له.<syntaxhighlight lang="liquid">
 +
{% assign url = "example.com" %}
 +
{{ "/index.html" | prepend: url }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
example.com/index.html
 +
</syntaxhighlight>
 +
 +
== <code>remove</code> ==
 +
يزيل كل ظهور لسلسلة نصية فرعية محدَّدة من سلسلة نصية.<syntaxhighlight lang="liquid">
 +
{{ "I strained to see the train through the rain" | remove: "rain" }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
I sted to see the t through the
 +
</syntaxhighlight>
 +
 +
== <code>remove_first</code> ==
 +
يزيل الظهور الأول فقط لسلسلة نصية فرعية محدَّدة من سلسلة نصية.<syntaxhighlight lang="liquid">
 +
{{ "I strained to see the train through the rain" | remove_first: "rain" }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
I sted to see the train through the rain
 +
</syntaxhighlight>
 +
 +
== <code>replace</code> ==
 +
يستبدل هذا المرشّح كلَّ ظهور لوسيطه الأول في سلسلة نصية بوسيطه الثاني.<syntaxhighlight lang="liquid">
 +
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Take your protein pills and put your helmet on
 +
</syntaxhighlight>
 +
 +
== <code>replace_first</code> ==
 +
يستبدل الظهور الأول فقط لوسيطه الأول في سلسلة نصية بوسيطه الثاني.<syntaxhighlight lang="liquid">
 +
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Take your protein pills and put my helmet on
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
+
 
قيمة الدخل في المثال التالي عبارة عن سلسلة نصية:
+
== <code>reverse</code> ==
{| class="wikitable"
+
يعكس هذا المرشّح ترتيب العناصر في مصفوفة، ولكن لا يمكنه عكس سلسلة نصية.<syntaxhighlight lang="liquid">
!الدخل
+
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
!الخرج
+
 
|-
+
{{ my_array | reverse | join: ", " }}
|<syntaxhighlight lang="liquid">
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
{{ "3.5" | floor }}
+
 
 +
 
 +
plums, peaches, oranges, apples
 +
</syntaxhighlight>لا يمكن استخدام المرشّح <code>reverse</code> مع سلسلة نصية مباشرةً، ولكن يمكنك تقسيم split السلسلة إلى مصفوفة، ثم عكس المصفوفة، وإعادة ضمها عن طريق ربط المرشّحات معًا كما يلي:<syntaxhighlight lang="liquid">
 +
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
.moT rojaM ot lortnoc dnuorG
 
</syntaxhighlight>
 
</syntaxhighlight>
|<syntaxhighlight lang="liquid">
+
 
 +
== <code>round</code> ==
 +
يُستخدَم لتقريب عدد إلى أقرب عدد صحيح أو إلى العدد المُمرَّر كوسيط الذي يمثل عدد المنازل العشرية.<syntaxhighlight lang="liquid">
 +
{{ 1.2 | round }}
 +
{{ 2.7 | round }}
 +
{{ 183.357 | round: 2 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
1
 
3
 
3
 +
183.36
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
=== join ===
+
== <code>rstrip</code> ==
يدمج هذا المرشّح العناصر الموجودة في مصفوفة في سلسلة نصية واحدة باستخدام الوسيط كفاصل بينها.
+
يزيل كل المسافات (مسافات tab والمسافات الفارغة والأسطر الجديدة) من جانب السلسلة الأيمن، ولا يؤثر على المسافات بين الكلمات.<syntaxhighlight lang="liquid">
{| class="wikitable"
+
{{ "          So much room for activities          " | rstrip }}!
!الدخل
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
!الخرج
+
          So much room for activities!
|-
+
</syntaxhighlight>
|<syntaxhighlight lang="liquid">
+
 
 +
== <code>size</code> ==
 +
يعيد هذا المرشّح عدد المحارف في سلسلة نصية أو عدد العناصر في مصفوفة.<syntaxhighlight lang="liquid">
 +
{{ "Ground control to Major Tom." | size }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
28
 +
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
 +
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
 +
 
 +
{{ my_array.size }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 
 +
 
 +
4
 +
</syntaxhighlight>
 +
يمكنك استخدام المرشّح <code>size</code> مع الصيغة النقطية عندما تحتاج إلى استخدام هذا المرشَح ضمن وسم كما يلي:<syntaxhighlight lang="liquid">
 +
{% if site.pages.size > 10 %}
 +
  This is a big website!
 +
{% endif %}
 +
</syntaxhighlight>
 +
 
 +
== <code>slice</code> ==
 +
يعيد هذا المرشّح سلسلة نصية فرعية مؤلفة من محرف واحد أو يعيد سلسلة من عناصر المصفوفة التي تبدأ بالفهرس المحدَّد باستخدام الوسيط الأول. يحدّد الوسيط الثاني الاختياري طول السلسلة الفرعية أو عدد عناصر المصفوفة المُعادة.
 +
 
 +
تٌرقَّم فهارس السلسلة النصية أو المصفوفة بدءًا من الصفر 0.<syntaxhighlight lang="liquid">
 +
{{ "Liquid" | slice: 0 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
L
 +
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
 +
{{ "Liquid" | slice: 2 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
q
 +
</syntaxhighlight>ومثال آخر:<syntaxhighlight lang="liquid">
 +
{{ "Liquid" | slice: 2, 5 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
quid
 +
</syntaxhighlight>قيمة الدخل عبارة عن مصفوفة في المثال التالي:<syntaxhighlight lang="liquid">
 +
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
 +
{{ beatles | slice: 1, 2 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 
 +
PaulGeorge
 +
</syntaxhighlight>إذا كان الوسيط الأول عبارة عن عدد سالب، تُحسَب الفهارس من نهاية السلسلة النصية.<syntaxhighlight lang="liquid">
 +
{{ "Liquid" | slice: -3, 2 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
ui
 +
</syntaxhighlight>
 +
 
 +
== <code>sort</code> ==
 +
يرتب هذا المرشّح عناصر المصفوفة بترتيب حسّاس لحالة الأحرف.<syntaxhighlight lang="liquid">
 +
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
 +
 
 +
{{ my_array | sort | join: ", " }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 
 +
 
 +
Sally Snake, giraffe, octopus, zebra
 +
</syntaxhighlight>
 +
يحدّد الوسيط الاختياري خاصيةً من عناصر المصفوفة لاستخدامها في عملية الترتيب.<syntaxhighlight lang="liquid">
 +
{% assign products_by_price = collection.products | sort: "price" %}
 +
{% for product in products_by_price %}
 +
  <h4>{{ product.title }}</h4>
 +
{% endfor %}
 +
</syntaxhighlight>
 +
 
 +
== <code>sort_natural</code> (خاص بالإصدار 4.0.0) ==
 +
يرتب العناصر في مصفوفة بترتيب غير حساس لحالة الأحرف.<syntaxhighlight lang="liquid">
 +
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
 +
 
 +
{{ my_array | sort_natural | join: ", " }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 
 +
 
 +
giraffe, octopus, Sally Snake, zebra
 +
</syntaxhighlight>
 +
يحدّد الوسيط الاختياري خاصيةً من عناصر المصفوفة لاستخدامها في عملية الترتيب.<syntaxhighlight lang="liquid">
 +
{% assign products_by_company = collection.products | sort_natural: "company" %}
 +
{% for product in products_by_company %}
 +
  <h4>{{ product.title }}</h4>
 +
{% endfor %}
 +
</syntaxhighlight>
 +
 
 +
== <code>split</code> ==
 +
يقسم هذا المرشّح سلسلة نصية إلى مصفوفة باستخدام وسيطه كفاصل بين العناصر، حيث يُستخدَم المرشّح <code>split</code> لتحويل العناصر المفصول بينها بفواصل من سلسلة نصية إلى مصفوفة.<syntaxhighlight lang="liquid">
 
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
 
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
  
{{ beatles | join: " and " }}
+
{% for member in beatles %}
 +
  {{ member }}
 +
{% endfor %}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 
 +
 
 +
 
 +
  John
 +
 
 +
  Paul
 +
 
 +
  George
 +
 
 +
  Ringo
 +
 
 +
</syntaxhighlight>
 +
 
 +
== <code>strip</code> ==
 +
يزيل هذا المرشّح كل المسافات (مسافات tabs والمسافات الفارغة والأسطر الجديدة) من جانبي السلسلة النصية الأيسر والأيمن، ولا يؤثر على المسافات بين الكلمات.<syntaxhighlight lang="liquid">
 +
{{ "          So much room for activities          " | strip }}!
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
So much room for activities!
 +
</syntaxhighlight>
 +
 
 +
== <code>strip_html</code> ==
 +
يزيل وسوم لغة HTML من سلسلة نصية.<syntaxhighlight lang="liquid">
 +
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Have you read Ulysses?
 +
</syntaxhighlight>
 +
 
 +
== <code>strip_newlines</code> ==
 +
يزيل محارف الأسطر الجديدة (فواصل الأسطر) من سلسلة نصية.<syntaxhighlight lang="liquid">
 +
{% capture string_with_newlines %}
 +
Hello
 +
there
 +
{% endcapture %}
 +
 
 +
{{ string_with_newlines | strip_newlines }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 
 +
 
 +
Hellothere
 +
</syntaxhighlight>
 +
 
 +
== <code>times</code> ==
 +
يضرب عددًا بعدد آخر.<syntaxhighlight lang="liquid">
 +
{{ 3 | times: 2 }}
 +
{{ 24 | times: 7 }}
 +
{{ 183.357 | times: 12 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
6
 +
168
 +
2200.284
 +
</syntaxhighlight>
 +
 
 +
== <code>truncate</code> ==
 +
يقتطع سلسلة نصية وصولًا إلى عدد المحارف الذي مُرِّر كوسيط. إذا كان عدد المحارف المحدَّد أقل من طول السلسلة، فستُلحَق علامة القطع ellipsis (...) بالسلسلة النصية وتُضمَّن في عدد المحارف.<syntaxhighlight lang="liquid">
 +
{{ "Ground control to Major Tom." | truncate: 20 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Ground control to...
 +
</syntaxhighlight>
 +
 
 +
=== علامات القطع المخصصة ===
 +
يأخذ المرشّح <code>truncate</code> وسيطًا ثانيًا اختياريًا يحدّد سلسلة المحارف المراد إلحاقها بالسلسلة المقتطَعة. علامة القطع هي (...) افتراضيًا، ولكن يمكنك تحديد سلسلة مختلفة.
 +
 
 +
يُحسَب طول الوسيط الثاني مع عدد المحارف المحدَّد بواسطة الوسيط الأول، فإذا أردت اقتطاع سلسلة نصية إلى 10 محارف بالضبط مع استخدام علامة القطع المكونة من 3 محارف مثلًا، فاستخدم القيمة 13 لوسيط المرشّح <code>truncate</code> الأول، لأن علامة القطع تُعَد 3 محارف.<syntaxhighlight lang="liquid">
 +
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Ground control, and so on
 +
</syntaxhighlight>
 +
 
 +
=== استخدام المرشح truncate بدون علامات القطع ===
 +
يمكنك اقتطاع سلسلة نصية إلى عدد المحارف المحدَّد بواسطة الوسيط الأول، مع تجنّب إظهار المحارف اللاحقة من خلال تمرير سلسلة نصية فارغة كوسيط ثانٍ.<syntaxhighlight lang="liquid">
 +
{{ "Ground control to Major Tom." | truncate: 20, "" }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Ground control to Ma
 +
</syntaxhighlight>
 +
 
 +
== <code>truncatewords</code> ==
 +
يقصّر هذا المرشّح من طول السلسلة النصية وصولًا إلى عدد الكلمات الممرَّرة كوسيط. إذا كان عدد الكلمات المحدَّد أقل من عدد الكلمات في السلسلة النصية، فستُلحَق علامة القطع (...) بالسلسلة النصية.<syntaxhighlight lang="liquid">
 +
{{ "Ground control to Major Tom." | truncatewords: 3 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Ground control to...
 +
</syntaxhighlight>
 +
 
 +
=== علامات القطع المخصصة ===
 +
يأخذ المرشّح <code>truncatewords</code> وسيطًا ثانيًا اختياريًا يحدّد سلسلة المحارف المراد إلحاقها بالسلسلة المقتطَعة. علامة القطع هي (...) افتراضيًا، ولكن يمكنك تحديد سلسلة مختلفة.<syntaxhighlight lang="liquid">
 +
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Ground control to--
 +
</syntaxhighlight>
 +
 
 +
=== استخدام المرشح truncatewords بدون علامات القطع ===
 +
يمكنك تجنّب إظهار المحارف اللاحقة من خلال تمرير سلسلة نصية فارغة كوسيط ثانٍ.<syntaxhighlight lang="liquid">
 +
{{ "Ground control to Major Tom." | truncatewords: 3, "" }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Ground control to
 +
</syntaxhighlight>
 +
 
 +
== <code>uniq</code> ==
 +
يزيل العناصر المكرَّرة في المصفوفة.<syntaxhighlight lang="liquid">
 +
{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}
 +
 
 +
{{ my_array | uniq | join: ", " }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 
 +
 
 +
ants, bugs, bees
 +
</syntaxhighlight>
 +
 
 +
== <code>upcase</code> ==
 +
يجعل هذا المرشّح كل حرف في السلسلة النصية باللغة الإنجليزية حرفًا كبيرًا، وليس له أي تأثير على السلاسل النصية التي تتكوّن كلها من أحرف كبيرة مسبقًا.<syntaxhighlight lang="liquid">
 +
{{ "Parker Moore" | upcase }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
PARKER MOORE
 +
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
 +
{{ "APPLE" | upcase }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
APPLE
 +
</syntaxhighlight>
 +
 
 +
== <code>url_decode</code> (خاص بالإصدار 4.0.0) ==
 +
يفك هذا المرشّح تشفير سلسلة نصية مُشفَّرة كعنوان URL أو مُشفَّرة باستخدام المرشّح <code>url_encode</code>.<syntaxhighlight lang="liquid">
 +
{{ "%27Stop%21%27+said+Fred" | url_decode }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
'Stop!' said Fred
 +
</syntaxhighlight>
 +
 
 +
== <code>url_encode</code> ==
 +
يحوّل محارف عنوان URL غير آمن في سلسلة نصية إلى محارف مُشفَّرة كنسبة مئوية.<syntaxhighlight lang="liquid">
 +
{{ "john@liquid.com" | url_encode }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
john%40liquid.com
 +
</syntaxhighlight>لاحظ أن المرشّح <code>url_encode</code> سيحول المسافة إلى إشارة <code>+</code> بدلًا من استخدام محرف النسبة المئوية المُشفَّر.<syntaxhighlight lang="liquid">
 +
{{ "Tetsuro Takara" | url_encode }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Tetsuro+Takara
 +
</syntaxhighlight>
 +
 
 +
== <code>where</code> (خاص بالإصدار 4.0.2) ==
 +
ينشئ هذا المرشّح مصفوفة تتضمن فقط الكائنات التي تملك قيمة خاصية معينة، أو أي قيمة صحيحة [[Liquid/truthy-and-falsy|truthy]] افتراضيًا.
 +
 
 +
افترض في المثال التالي أن لديك قائمة بالمنتجات وتريد عرض منتجات مطبخك منفصلة عن بعضها البعض. يمكنك باستخدام المرشّح <code>where</code> إنشاء مصفوفة تحتوي فقط على المنتجات التي لها النوع <code>"type"</code> مطبخ <code>"kitchen"</code>.<syntaxhighlight lang="liquid">
 +
All products:
 +
{% for product in products %}
 +
- {{ product.title }}
 +
{% endfor %}
 +
 
 +
{% assign kitchen_products = products | where: "type", "kitchen" %}
 +
 
 +
Kitchen products:
 +
{% for product in kitchen_products %}
 +
- {{ product.title }}
 +
{% endfor %}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
All products:
 +
- Vacuum
 +
- Spatula
 +
- Television
 +
- Garlic press
 +
 
 +
Kitchen products:
 +
- Spatula
 +
- Garlic press
 +
</syntaxhighlight>افترض أن لديك قائمة بالمنتجات وتريد فقط إظهار المنتجات المتاحة للشراء. يمكنك استخدام المرشّح <code>where</code> مع اسم خاصية ولكن بدون قيمة مستهدفة لتضمين جميع المنتجات ذات القيمة الصحيحة truthy وهي <code>"available"</code>.<syntaxhighlight lang="liquid">
 +
All products:
 +
{% for product in products %}
 +
- {{ product.title }}
 +
{% endfor %}
 +
 
 +
{% assign available_products = products | where: "available" %}
 +
 
 +
Available products:
 +
{% for product in available_products %}
 +
- {{ product.title }}
 +
{% endfor %}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
All products:
 +
- Coffee mug
 +
- Limited edition sneakers
 +
- Boring sneakers
 +
 
 +
Available products:
 +
- Coffee mug
 +
- Boring sneakers
 +
</syntaxhighlight>يمكن أيضًا استخدام المرشّح <code>where</code> للعثور على كائن في مصفوفة عند دمجه مع المرشّح <code>first</code>. لنفترض مثلًا أنك تريد عرض القميص shirt في مجموعتك الجديدة لفصل الخريف.<syntaxhighlight lang="liquid">
 +
{% assign new_shirt = products | where: "type", "shirt" | first %}
 +
 
 +
Featured product: {{ new_shirt.title }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
Featured product: Hawaiian print sweater vest
 
</syntaxhighlight>
 
</syntaxhighlight>
|
 
  
<code>John and Paul and George and Ringo</code>
+
== مصادر ==
|}
+
 
 +
* [https://shopify.github.io/liquid/filters/abs/ صفحات Filters في توثيق Liquid الرسمي.]
 +
[[تصنيف:Liquid]]

المراجعة الحالية بتاريخ 13:30، 6 أغسطس 2021

تعرض هذه الصفحة كل المرشحات الموجودة في Liquid مع أمثلة على كل واحدة منها وذكر كل التفاصيل المتعلقة بها، يمكنك استعمال الفهرس للانتقال للمرشح المطلوب مباشرةً.

abs

يعيد هذا المرشّح قيمة العدد المطلقة.

{{ -17 | abs }}
{{ 4 | abs }}

الخرج:

17
4

يعمل المرشّح abs أيضًا مع سلسلة نصية تحتوي على عدد فقط.

{{ "-19.86" | abs }}

الخرج:

19.86

append

يضيف هذا المرشّح سلسلة نصية محدَّدة إلى نهاية سلسلة نصية أخرى.

{{ "/my/fancy/url" | append: ".html" }}

الخرج:

/my/fancy/url.html

يمكن للمرشّح append أيضًا قبول متغير كوسيطٍ له.

{% assign filename = "/index.html" %}
{{ "website.com" | append: filename }}

الخرج:

website.com/index.html

at_least (خاص بالإصدار 4.0.1)

يحدّد قيمة عددٍ ما بالقيمة الدنيا.

{{ 4 | at_least: 5 }}
{{ 4 | at_least: 3 }}

الخرج:

5
4

at_most (خاص بالإصدار 4.0.1)

يحدّد قيمة عددٍ ما بالقيمة العليا.

{{ 4 | at_most: 5 }}
{{ 4 | at_most: 3 }}

الخرج:

4
3

capitalize

يجعل هذا المرشّح الحرف الأول من سلسلة نصية باللغة الإنجليزية حرفًا كبيرًا ويحوّل الأحرف المتبقية إلى أحرف صغيرة.

{{ "title" | capitalize }}

الخرج:

Title

يُكتَب الحرف الأول فقط من سلسلة نصية إنجليزية كحرف كبير، لذلك لا تُكتَب الأحرف الأولى من الكلمات اللاحقة بأحرف كبيرة:

{{ "my GREAT title" | capitalize }}

الخرج:

My great title

ceil

يقرّب هذا المرشّح الدخل إلى أقرب وأكبر عدد صحيح، إذ تحاول لغة Liquid تحويل الدخل إلى عدد قبل تطبيق المرشّح.

{{ 1.2 | ceil }}
{{ 2.0 | ceil }}
{{ 183.357 | ceil }}

الخرج:

2
2
184

سنستخدم في المثال التالي قيمة الدخل على أنها سلسلة نصية:

{{ "3.5" | ceil }}

الخرج:

4

compact (خاص بالإصدار 4.0.0)

يزيل هذا المرشّح أي قيم nil من المصفوفة.

افترض في المثال التالي أن site.pages عبارة عن مجموعة من صفحات محتوى موقع ويب، وبعض هذه الصفحات لها سِمة attribute تسمى category تحدّد فئة محتوى الصفحة. إذا ربطنا هذه الفئات مع مصفوفة عبر map، فقد تكون بعض قيم عناصر المصفوفة nil إن لم تتضمن صفحةٌ ما السمة category.

{% assign site_categories = site.pages | map: "category" %}

{% for category in site_categories %}
- {{ category }}
{% endfor %}

الخرج:

- business
- celebrities
-
- lifestyle
- sports
-
- technology

لكن يمكننا إزالة جميع قيم nil في المصفوفة باستخدام المرشّح compact عند إنشاء المصفوفة site_categories.

{% assign site_categories = site.pages | map: "category" | compact %}

{% for category in site_categories %}
- {{ category }}
{% endfor %}

الخرج:

- business
- celebrities
- lifestyle
- sports
- technology

concat (خاص بالإصدار 4.0.0)

يربط هذا المرشّح (أو يضم معًا) مصفوفات متعددة، إذ تحتوي المصفوفة الناتجة على جميع العناصر من مصفوفات الدخل.

{% assign fruits = "apples, oranges, peaches" | split: ", " %}
{% assign vegetables = "carrots, turnips, potatoes" | split: ", " %}

{% assign everything = fruits | concat: vegetables %}

{% for item in everything %}
- {{ item }}
{% endfor %}

الخرج:

- apples
- oranges
- peaches
- carrots
- turnips
- potatoes

يمكنك تجميع مرشّحات concat متعددة معًا لضم أكثر من مصفوفتين.

{% assign furniture = "chairs, tables, shelves" | split: ", " %}

{% assign everything = fruits | concat: vegetables | concat: furniture %}

{% for item in everything %}
- {{ item }}
{% endfor %}

الخرج:

- apples
- oranges
- peaches
- carrots
- turnips
- potatoes
- chairs
- tables
- shelves

date

يحوّل هذا المرشّح علامة زمنية timestamp إلى تنسيق تاريخ date آخر، فتنسيق هذه الصيغة هو strftime نفسه، بينما يستخدم الدخل تنسيق Time.parse الخاص بلغة روبي Ruby نفسه.

{{ article.published_at | date: "%a, %b %d, %y" }}

الخرج:

Fri, Jul 17, 15

إليك مثال آخر:

{{ article.published_at | date: "%Y" }}

الخرج:

2015

يعمل المرشّح date مع السلاسل النصية إذا احتوت على تواريخ جيدة التنسيق.

{{ "March 14, 2016" | date: "%b %d, %y" }}

الخرج:

Mar 14, 16

يمكنك الحصول على الوقت الحالي من خلال تمرير الكلمة الخاصة "now" (أو "today") إلى المرشّح date.

This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}.

الخرج:

This page was last updated at 2021-04-28 17:52.

لاحظ أن القيمة ستكون هي الوقت الحالي لآخر إنشاء للصفحة من القالب، وليس وقت تقديم الصفحة إلى المستخدم في حالة التخزين المؤقت أو إنشاء موقع ساكن.

default

يضبط قيمة افتراضية للمتغير الذي لا يملك قيمة مُسنَدة. سيظهِر المرشّح default قيمته إذا كان الدخل قيمة nil أو false أو قيمة فارغة.

لم تُحدَّد قيمة المتغير product_price، لذلك اُستخدِمت القيمة الافتراضية في المثال التالي:

{{ product_price | default: 2.99 }}

الخرج:

2.99

حُدِّدت قيمة المتغير product_price، لذلك لم تُستخدَم القيمة الافتراضية في المثال التالي:

{% assign product_price = 4.99 %}
{{ product_price | default: 2.99 }}

الخرج:

4.99

قيمة المتغير product_price فارغة، لذلك اُستخدِمت القيمة الافتراضية في المثال التالي:

{% assign product_price = "" %}
{{ product_price | default: 2.99 }}

الخرج:

2.99

السماح بالقيمة false (خاص بالإصدار 5.0.0)

يمكن السماح للمتغيرات بأن تعيد القيمة false بدلًا من القيمة الافتراضية من خلال استخدام العامل allow_false.

{% assign display_price = false %}
{{ display_price | default: true, allow_false: true }}

الخرج:

false

divided_by

يقسم هذا المرشّح عددًا على عددٍ آخر.

تُقرَّب النتيجة إلى أقرب وأصغر عدد صحيح (كالمرشّح floor) إذا كان المقسوم عليه عددًا صحيحًا.

{{ 16 | divided_by: 4 }}
{{ 5 | divided_by: 3 }}

الخرج:

4
1

التحكم بعملية التقريب

ينتج عن المرشّح divided_by نتيجة من نوع المقسوم عليه، أي إذا قسمت على عدد صحيح، فستكون النتيجة عددًا صحيحًا. إذا قسمت على عدد عشري float، فستكون النتيجة عددًا عشريًا.

المقسوم عليه في المثال التالي هو عدد صحيح:

{{ 20 | divided_by: 7 }}

الخرج:

2

المقسوم عليه في المثال التالي هو عدد عشري:

{{ 20 | divided_by: 7.0 }}

الخرج:

2.857142857142857

تغيير أنواع المتغيرات

قد ترغب في استخدام متغير كمقسوم عليه، حيث لا يمكنك في هذه الحالة إضافة ‎.0 لتحويله إلى عدد عشري ببساطة، ولكن يمكنك إسناد assign نسخة من المتغير محوَّلة إلى عدد عشري باستخدام المرشّح times.

سنقسم في المثال التالي على متغير يحتوي على عدد صحيح، لذلك سنحصل على عدد صحيح:

{% assign my_integer = 7 %}
{{ 20 | divided_by: my_integer }}

الخرج:

2

نضرب المتغير بالعدد 1.0 باستخدام المرشّح times لنحصل على عدد عشري، ثم نقسم على عدد عشري في المثال التالي:

{% assign my_integer = 7 %}
{% assign my_float = my_integer | times: 1.0 %}
{{ 20 | divided_by: my_float }}

الخرج:

2.857142857142857

downcase

يجعل هذا المرشّح كل حرف في سلسلة نصية بحالة الأحرف الصغيرة، وليس له تأثير على السلاسل النصية التي تتكون من أحرف صغيرة مسبقًا.

{{ "Parker Moore" | downcase }}

الخرج:

parker moore

إليك مثال آخر:

{{ "apple" | downcase }}

الخرج:

apple

escape

يطبّق هذا المرشّح عملية الهروب على سلسلة نصية عن طريق استبدال المحارف بتسلسلات الهروب escape sequences (بحيث يمكن استخدام هذه السلسلة في عنوان URL مثلًا)، ولا يغيّر السلاسل النصية التي ليس لديها أي شيء لتطبيق عملية الهروب عليه.

{{ "Have you read 'James & the Giant Peach'?" | escape }}

الخرج:

Have you read &#39;James &amp; the Giant Peach&#39;?

إليك مثال آخر:

{{ "Tetsuro Takara" | escape }}

الخرج:

Tetsuro Takara

escape_once

يطبّق عملية الهروب على سلسلة نصية بدون تغيير الكيانات المُطبَّق عليها الهروب مسبقًا، ولا يغيّر السلاسل النصية التي ليس لديها أي شيء لتطبيق عملية الهروب عليه.

{{ "1 < 2 & 3" | escape_once }}

الخرج:

1 &lt; 2 &amp; 3

إليك مثال آخر:

{{ "1 &lt; 2 &amp; 3" | escape_once }}

الخرج:

1 &lt; 2 &amp; 3

first

يعيد هذا المرشّح العنصر الأول من مصفوفة.

{{ "Ground control to Major Tom." | split: " " | first }}

الخرج:

Ground

إليك مثال آخر:

{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}

{{ my_array.first }}

الخرج:

zebra

يمكنك استخدام المرشّح first مع الصيغة النقطية dot notation عندما تحتاج إلى استخدام المرشّح ضمن وسم كما يلي:

{% if my_array.first == "zebra" %}
  Here comes a zebra!
{% endif %}

floor

يقرّب هذا المرشّح الدخل إلى أقرب وأصغر عدد صحيح، حيث تحاول لغة Liquid تحويل الدخل إلى عدد قبل تطبيق المرشح.

{{ 1.2 | floor }}
{{ 2.0 | floor }}
{{ 183.357 | floor }}

الخرج:

1
2
183

قيمة الدخل في المثال التالي عبارة عن سلسلة نصية:

{{ "3.5" | floor }}

الخرج:

3

join

يدمج هذا المرشّح العناصر الموجودة في مصفوفة ضمن سلسلة نصية واحدة باستخدام وسيطه كفاصل بينها.

{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}

{{ beatles | join: " and " }}

الخرج:

John and Paul and George and Ringo

last

يعيد هذا المرشّح العنصر الأخير من مصفوفة.

{{ "Ground control to Major Tom." | split: " " | last }}

الخرج:

Tom.

إليك مثال آخر:

{% assign my_array = "zebra, octopus, giraffe, tiger" | split: ", " %}

{{ my_array.last }}

الخرج:

tiger

يمكنك استخدام المرشّح last مع الصيغة النقطية عندما تحتاج إلى استخدام هذا المرشّح ضمن وسم كما يلي:

{% if my_array.last == "tiger" %}
  There goes a tiger!
{% endif %}

lstrip

يزيل هذا المرشّح كل المسافات (مسافات tab والمسافات الفارغة والأسطر الجديدة) من جانب السلسلة النصية الأيسر، ولا يؤثر على المسافات بين الكلمات.

{{ "          So much room for activities          " | lstrip }}!

الخرج:

So much room for activities          !

map

يُنشئ هذا المرشّح مصفوفة من القيم عن طريق استخراج قيم خاصيةٍ مسمَّاة من كائن آخر.

افترض في المثال التالي أن الكائن site.pages يحتوي على جميع البيانات الوصفية metadata لموقع ويب. يؤدي استخدام الوسم assign مع المرشّح map إلى إنشاء متغير يحتوي فقط على قيم خصائص الفئة category لكل شيء في الكائن site.pages.

{% assign all_categories = site.pages | map: "category" %}

{% for item in all_categories %}
- {{ item }}
{% endfor %}

الخرج:

- business
- celebrities
- lifestyle
- sports
- technology

minus

يطرح عددًا من عدد آخر.

{{ 4 | minus: 2 }}
{{ 16 | minus: 4 }}
{{ 183.357 | minus: 12 }}

الخرج:

2
12
171.357

modulo

يعيد هذا المرشّح الباقي من عملية قسمة.

{{ 3 | modulo: 2 }}
{{ 24 | modulo: 7 }}
{{ 183.357 | modulo: 12 }}

الخرج:

1
3
3.357

newline_to_br

يدخل هذا المرشّح الفاصل السطري (<br /‎>) الخاص بلغة HTML أمام كل سطر جديد (‎\n) في سلسلة نصية.

{% capture string_with_newlines %}
Hello
there
{% endcapture %}

{{ string_with_newlines | newline_to_br }}

الخرج:

<br />
Hello<br />
there<br />

plus

يجمع هذا المرشّح عددين.

{{ 4 | plus: 2 }}
{{ 16 | plus: 4 }}
{{ 183.357 | plus: 12 }}

الخرج:

6
20
195.357

prepend

يضيف هذا المرشّح سلسلة نصية محدَّدة إلى بداية سلسلة نصية أخرى.

{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}

الخرج:

Some fruit: apples, oranges, and bananas

يمكن أن يقبل المرشّح prepend أيضًا متغيرًا كوسيطٍ له.

{% assign url = "example.com" %}
{{ "/index.html" | prepend: url }}

الخرج:

example.com/index.html

remove

يزيل كل ظهور لسلسلة نصية فرعية محدَّدة من سلسلة نصية.

{{ "I strained to see the train through the rain" | remove: "rain" }}

الخرج:

I sted to see the t through the

remove_first

يزيل الظهور الأول فقط لسلسلة نصية فرعية محدَّدة من سلسلة نصية.

{{ "I strained to see the train through the rain" | remove_first: "rain" }}

الخرج:

I sted to see the train through the rain

replace

يستبدل هذا المرشّح كلَّ ظهور لوسيطه الأول في سلسلة نصية بوسيطه الثاني.

{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}

الخرج:

Take your protein pills and put your helmet on

replace_first

يستبدل الظهور الأول فقط لوسيطه الأول في سلسلة نصية بوسيطه الثاني.

{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}

الخرج:

Take your protein pills and put my helmet on

reverse

يعكس هذا المرشّح ترتيب العناصر في مصفوفة، ولكن لا يمكنه عكس سلسلة نصية.

{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}

{{ my_array | reverse | join: ", " }}

الخرج:

plums, peaches, oranges, apples

لا يمكن استخدام المرشّح reverse مع سلسلة نصية مباشرةً، ولكن يمكنك تقسيم split السلسلة إلى مصفوفة، ثم عكس المصفوفة، وإعادة ضمها عن طريق ربط المرشّحات معًا كما يلي:

{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}

الخرج:

.moT rojaM ot lortnoc dnuorG

round

يُستخدَم لتقريب عدد إلى أقرب عدد صحيح أو إلى العدد المُمرَّر كوسيط الذي يمثل عدد المنازل العشرية.

{{ 1.2 | round }}
{{ 2.7 | round }}
{{ 183.357 | round: 2 }}

الخرج:

1
3
183.36

rstrip

يزيل كل المسافات (مسافات tab والمسافات الفارغة والأسطر الجديدة) من جانب السلسلة الأيمن، ولا يؤثر على المسافات بين الكلمات.

{{ "          So much room for activities          " | rstrip }}!

الخرج:

          So much room for activities!

size

يعيد هذا المرشّح عدد المحارف في سلسلة نصية أو عدد العناصر في مصفوفة.

{{ "Ground control to Major Tom." | size }}

الخرج:

28

إليك مثال آخر:

{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}

{{ my_array.size }}

الخرج:

4

يمكنك استخدام المرشّح size مع الصيغة النقطية عندما تحتاج إلى استخدام هذا المرشَح ضمن وسم كما يلي:

{% if site.pages.size > 10 %}
  This is a big website!
{% endif %}

slice

يعيد هذا المرشّح سلسلة نصية فرعية مؤلفة من محرف واحد أو يعيد سلسلة من عناصر المصفوفة التي تبدأ بالفهرس المحدَّد باستخدام الوسيط الأول. يحدّد الوسيط الثاني الاختياري طول السلسلة الفرعية أو عدد عناصر المصفوفة المُعادة.

تٌرقَّم فهارس السلسلة النصية أو المصفوفة بدءًا من الصفر 0.

{{ "Liquid" | slice: 0 }}

الخرج:

L

إليك مثال آخر:

{{ "Liquid" | slice: 2 }}

الخرج:

q

ومثال آخر:

{{ "Liquid" | slice: 2, 5 }}

الخرج:

quid

قيمة الدخل عبارة عن مصفوفة في المثال التالي:

{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
{{ beatles | slice: 1, 2 }}

الخرج:

PaulGeorge

إذا كان الوسيط الأول عبارة عن عدد سالب، تُحسَب الفهارس من نهاية السلسلة النصية.

{{ "Liquid" | slice: -3, 2 }}

الخرج:

ui

sort

يرتب هذا المرشّح عناصر المصفوفة بترتيب حسّاس لحالة الأحرف.

{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}

{{ my_array | sort | join: ", " }}

الخرج:

Sally Snake, giraffe, octopus, zebra

يحدّد الوسيط الاختياري خاصيةً من عناصر المصفوفة لاستخدامها في عملية الترتيب.

{% assign products_by_price = collection.products | sort: "price" %}
{% for product in products_by_price %}
  <h4>{{ product.title }}</h4>
{% endfor %}

sort_natural (خاص بالإصدار 4.0.0)

يرتب العناصر في مصفوفة بترتيب غير حساس لحالة الأحرف.

{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}

{{ my_array | sort_natural | join: ", " }}

الخرج:

giraffe, octopus, Sally Snake, zebra

يحدّد الوسيط الاختياري خاصيةً من عناصر المصفوفة لاستخدامها في عملية الترتيب.

{% assign products_by_company = collection.products | sort_natural: "company" %}
{% for product in products_by_company %}
  <h4>{{ product.title }}</h4>
{% endfor %}

split

يقسم هذا المرشّح سلسلة نصية إلى مصفوفة باستخدام وسيطه كفاصل بين العناصر، حيث يُستخدَم المرشّح split لتحويل العناصر المفصول بينها بفواصل من سلسلة نصية إلى مصفوفة.

{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}

{% for member in beatles %}
  {{ member }}
{% endfor %}

الخرج:

  John

  Paul

  George

  Ringo

strip

يزيل هذا المرشّح كل المسافات (مسافات tabs والمسافات الفارغة والأسطر الجديدة) من جانبي السلسلة النصية الأيسر والأيمن، ولا يؤثر على المسافات بين الكلمات.

{{ "          So much room for activities          " | strip }}!

الخرج:

So much room for activities!

strip_html

يزيل وسوم لغة HTML من سلسلة نصية.

{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}

الخرج:

Have you read Ulysses?

strip_newlines

يزيل محارف الأسطر الجديدة (فواصل الأسطر) من سلسلة نصية.

{% capture string_with_newlines %}
Hello
there
{% endcapture %}

{{ string_with_newlines | strip_newlines }}

الخرج:

Hellothere

times

يضرب عددًا بعدد آخر.

{{ 3 | times: 2 }}
{{ 24 | times: 7 }}
{{ 183.357 | times: 12 }}

الخرج:

6
168
2200.284

truncate

يقتطع سلسلة نصية وصولًا إلى عدد المحارف الذي مُرِّر كوسيط. إذا كان عدد المحارف المحدَّد أقل من طول السلسلة، فستُلحَق علامة القطع ellipsis (...) بالسلسلة النصية وتُضمَّن في عدد المحارف.

{{ "Ground control to Major Tom." | truncate: 20 }}

الخرج:

Ground control to...

علامات القطع المخصصة

يأخذ المرشّح truncate وسيطًا ثانيًا اختياريًا يحدّد سلسلة المحارف المراد إلحاقها بالسلسلة المقتطَعة. علامة القطع هي (...) افتراضيًا، ولكن يمكنك تحديد سلسلة مختلفة.

يُحسَب طول الوسيط الثاني مع عدد المحارف المحدَّد بواسطة الوسيط الأول، فإذا أردت اقتطاع سلسلة نصية إلى 10 محارف بالضبط مع استخدام علامة القطع المكونة من 3 محارف مثلًا، فاستخدم القيمة 13 لوسيط المرشّح truncate الأول، لأن علامة القطع تُعَد 3 محارف.

{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}

الخرج:

Ground control, and so on

استخدام المرشح truncate بدون علامات القطع

يمكنك اقتطاع سلسلة نصية إلى عدد المحارف المحدَّد بواسطة الوسيط الأول، مع تجنّب إظهار المحارف اللاحقة من خلال تمرير سلسلة نصية فارغة كوسيط ثانٍ.

{{ "Ground control to Major Tom." | truncate: 20, "" }}

الخرج:

Ground control to Ma

truncatewords

يقصّر هذا المرشّح من طول السلسلة النصية وصولًا إلى عدد الكلمات الممرَّرة كوسيط. إذا كان عدد الكلمات المحدَّد أقل من عدد الكلمات في السلسلة النصية، فستُلحَق علامة القطع (...) بالسلسلة النصية.

{{ "Ground control to Major Tom." | truncatewords: 3 }}

الخرج:

Ground control to...

علامات القطع المخصصة

يأخذ المرشّح truncatewords وسيطًا ثانيًا اختياريًا يحدّد سلسلة المحارف المراد إلحاقها بالسلسلة المقتطَعة. علامة القطع هي (...) افتراضيًا، ولكن يمكنك تحديد سلسلة مختلفة.

{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}

الخرج:

Ground control to--

استخدام المرشح truncatewords بدون علامات القطع

يمكنك تجنّب إظهار المحارف اللاحقة من خلال تمرير سلسلة نصية فارغة كوسيط ثانٍ.

{{ "Ground control to Major Tom." | truncatewords: 3, "" }}

الخرج:

Ground control to

uniq

يزيل العناصر المكرَّرة في المصفوفة.

{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}

{{ my_array | uniq | join: ", " }}

الخرج:

ants, bugs, bees

upcase

يجعل هذا المرشّح كل حرف في السلسلة النصية باللغة الإنجليزية حرفًا كبيرًا، وليس له أي تأثير على السلاسل النصية التي تتكوّن كلها من أحرف كبيرة مسبقًا.

{{ "Parker Moore" | upcase }}

الخرج:

PARKER MOORE

إليك مثال آخر:

{{ "APPLE" | upcase }}

الخرج:

APPLE

url_decode (خاص بالإصدار 4.0.0)

يفك هذا المرشّح تشفير سلسلة نصية مُشفَّرة كعنوان URL أو مُشفَّرة باستخدام المرشّح url_encode.

{{ "%27Stop%21%27+said+Fred" | url_decode }}

الخرج:

'Stop!' said Fred

url_encode

يحوّل محارف عنوان URL غير آمن في سلسلة نصية إلى محارف مُشفَّرة كنسبة مئوية.

{{ "john@liquid.com" | url_encode }}

الخرج:

john%40liquid.com

لاحظ أن المرشّح url_encode سيحول المسافة إلى إشارة + بدلًا من استخدام محرف النسبة المئوية المُشفَّر.

{{ "Tetsuro Takara" | url_encode }}

الخرج:

Tetsuro+Takara

where (خاص بالإصدار 4.0.2)

ينشئ هذا المرشّح مصفوفة تتضمن فقط الكائنات التي تملك قيمة خاصية معينة، أو أي قيمة صحيحة truthy افتراضيًا.

افترض في المثال التالي أن لديك قائمة بالمنتجات وتريد عرض منتجات مطبخك منفصلة عن بعضها البعض. يمكنك باستخدام المرشّح where إنشاء مصفوفة تحتوي فقط على المنتجات التي لها النوع "type" مطبخ "kitchen".

All products:
{% for product in products %}
- {{ product.title }}
{% endfor %}

{% assign kitchen_products = products | where: "type", "kitchen" %}

Kitchen products:
{% for product in kitchen_products %}
- {{ product.title }}
{% endfor %}

الخرج:

All products:
- Vacuum
- Spatula
- Television
- Garlic press

Kitchen products:
- Spatula
- Garlic press

افترض أن لديك قائمة بالمنتجات وتريد فقط إظهار المنتجات المتاحة للشراء. يمكنك استخدام المرشّح where مع اسم خاصية ولكن بدون قيمة مستهدفة لتضمين جميع المنتجات ذات القيمة الصحيحة truthy وهي "available".

All products:
{% for product in products %}
- {{ product.title }}
{% endfor %}

{% assign available_products = products | where: "available" %}

Available products:
{% for product in available_products %}
- {{ product.title }}
{% endfor %}

الخرج:

All products:
- Coffee mug
- Limited edition sneakers
- Boring sneakers

Available products:
- Coffee mug
- Boring sneakers

يمكن أيضًا استخدام المرشّح where للعثور على كائن في مصفوفة عند دمجه مع المرشّح first. لنفترض مثلًا أنك تريد عرض القميص shirt في مجموعتك الجديدة لفصل الخريف.

{% assign new_shirt = products | where: "type", "shirt" | first %}

Featured product: {{ new_shirt.title }}

الخرج:

Featured product: Hawaiian print sweater vest

مصادر