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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
 
(مراجعتان متوسطتان بواسطة مستخدم واحد آخر غير معروضتين)
سطر 1: سطر 1:
 
<noinclude>{{DISPLAYTITLE:المرشحات Filters في Liquid}}</noinclude>
 
<noinclude>{{DISPLAYTITLE:المرشحات Filters في Liquid}}</noinclude>
== abs ==
+
تعرض هذه الصفحة كل المرشحات الموجودة في Liquid مع أمثلة على كل واحدة منها وذكر كل التفاصيل المتعلقة بها، يمكنك استعمال الفهرس للانتقال للمرشح المطلوب مباشرةً.
 +
 
 +
== <code>abs</code> ==
 
يعيد هذا المرشّح قيمة العدد المطلقة.<syntaxhighlight lang="liquid">
 
يعيد هذا المرشّح قيمة العدد المطلقة.<syntaxhighlight lang="liquid">
 
{{ -17 | abs }}
 
{{ -17 | abs }}
سطر 12: سطر 14:
 
19.86
 
19.86
 
</syntaxhighlight>
 
</syntaxhighlight>
== append ==
+
== <code>append</code> ==
يضيف هذا المرشّح سلسلة نصية محدَّدة إلى نهاية سلسلة نصية أخرى.
+
يضيف هذا المرشّح سلسلة نصية محدَّدة إلى نهاية سلسلة نصية أخرى.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "/my/fancy/url" | append: ".html" }}
 
{{ "/my/fancy/url" | append: ".html" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
/my/fancy/url.html
 
/my/fancy/url.html
</syntaxhighlight>
+
</syntaxhighlight>يمكن للمرشّح <code>append</code> أيضًا قبول متغير كوسيطٍ له.<syntaxhighlight lang="liquid">
|}
 
يمكن للمرشّح <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> عبارة عن مجموعة من صفحات محتوى موقع ويب، وبعض هذه الصفحات لها سِمة attribute تسمى <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" %}
  
سطر 128: سطر 80:
 
- {{ category }}
 
- {{ category }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
- business
 
- business
 
- celebrities
 
- celebrities
سطر 137: سطر 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 %}
  
سطر 150: سطر 94:
 
- {{ category }}
 
- {{ category }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
- business
 
- business
 
- celebrities
 
- celebrities
سطر 158: سطر 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: ", " %}
سطر 175: سطر 112:
 
- {{ item }}
 
- {{ item }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
- apples
 
- apples
 
- oranges
 
- oranges
سطر 183: سطر 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: ", " %}
  
سطر 198: سطر 127:
 
- {{ item }}
 
- {{ item }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
- apples
 
- apples
 
- oranges
 
- oranges
سطر 210: سطر 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|روبي]] [[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> (خاص بالإصدار 5.0.0)  ===
يمكن السماح للمتغيرات بأن تعيد القيمة <code>false</code> بدلًا من القيمة الافتراضية من خلال استخدام العامل <code>allow_false</code>.
+
يمكن السماح للمتغيرات بأن تعيد القيمة <code>false</code> بدلًا من القيمة الافتراضية من خلال استخدام العامل <code>allow_false</code>.<syntaxhighlight lang="liquid">
{| 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> ==
 
== <code>downcase</code> ==
يجعل هذا المرشّح كل حرف في سلسلة نصية بحالة الأحرف الصغيرة، وليس له تأثير على السلاسل النصية التي تتكون من أحرف صغيرة مسبقًا.
+
يجعل هذا المرشّح كل حرف في سلسلة نصية بحالة الأحرف الصغيرة، وليس له تأثير على السلاسل النصية التي تتكون من أحرف صغيرة مسبقًا.<syntaxhighlight lang="liquid">
{| 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>
|}
 
  
 
== <code>escape</code> ==
 
== <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>
|}
 
  
 
== <code>escape_once</code> ==
 
== <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>
|}
 
  
 
== <code>first</code> ==
 
== <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>zebra</code>
 
|}
 
 
يمكنك استخدام المرشّح <code>first</code> مع الصيغة النقطية dot notation عندما تحتاج إلى استخدام المرشّح ضمن وسم كما يلي:<syntaxhighlight lang="liquid">
 
يمكنك استخدام المرشّح <code>first</code> مع الصيغة النقطية dot notation عندما تحتاج إلى استخدام المرشّح ضمن وسم كما يلي:<syntaxhighlight lang="liquid">
 
{% if my_array.first == "zebra" %}
 
{% if my_array.first == "zebra" %}
سطر 504: سطر 285:
  
 
== <code>floor</code> ==
 
== <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>قيمة الدخل في المثال التالي عبارة عن سلسلة نصية:<syntaxhighlight lang="liquid">
|}
 
قيمة الدخل في المثال التالي عبارة عن سلسلة نصية:
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "3.5" | floor }}
 
{{ "3.5" | floor }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
3
 
3
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>join</code> ==
 
== <code>join</code> ==
يدمج هذا المرشّح العناصر الموجودة في مصفوفة ضمن سلسلة نصية واحدة باستخدام وسيطه كفاصل بينها.
+
يدمج هذا المرشّح العناصر الموجودة في مصفوفة ضمن سلسلة نصية واحدة باستخدام وسيطه كفاصل بينها.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
 
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
  
 
{{ beatles | join: " and " }}
 
{{ beatles | join: " and " }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
 +
John and Paul and George and Ringo
 
</syntaxhighlight>
 
</syntaxhighlight>
|
 
 
<code>John and Paul and George and Ringo</code>
 
|}
 
  
 
== <code>last</code> ==
 
== <code>last</code> ==
يعيد هذا المرشّح العنصر الأخير من مصفوفة.
+
يعيد هذا المرشّح العنصر الأخير من مصفوفة.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Ground control to Major Tom." | split: " " | last }}
 
{{ "Ground control to Major Tom." | split: " " | last }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|
+
Tom.
<code>Tom.</code>
+
</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.last }}
 
{{ my_array.last }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
 +
tiger
 
</syntaxhighlight>
 
</syntaxhighlight>
|
 
 
<code>tiger</code>
 
|}
 
 
يمكنك استخدام المرشّح <code>last</code> مع الصيغة النقطية عندما تحتاج إلى استخدام هذا المرشّح ضمن وسم كما يلي:<syntaxhighlight lang="liquid">
 
يمكنك استخدام المرشّح <code>last</code> مع الصيغة النقطية عندما تحتاج إلى استخدام هذا المرشّح ضمن وسم كما يلي:<syntaxhighlight lang="liquid">
 
{% if my_array.last == "tiger" %}
 
{% if my_array.last == "tiger" %}
سطر 581: سطر 331:
  
 
== <code>lstrip</code> ==
 
== <code>lstrip</code> ==
يزيل هذا المرشّح كل المسافات (مسافات tab والمسافات الفارغة والأسطر الجديدة) من جانب السلسلة النصية الأيسر، ولا يؤثر على المسافات بين الكلمات.
+
يزيل هذا المرشّح كل المسافات (مسافات tab والمسافات الفارغة والأسطر الجديدة) من جانب السلسلة النصية الأيسر، ولا يؤثر على المسافات بين الكلمات.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "          So much room for activities          " | lstrip }}!
 
{{ "          So much room for activities          " | lstrip }}!
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
So much room for activities          !
 
So much room for activities          !
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>map</code> ==
 
== <code>map</code> ==
 
يُنشئ هذا المرشّح مصفوفة من القيم عن طريق استخراج قيم خاصيةٍ مسمَّاة من كائن آخر.
 
يُنشئ هذا المرشّح مصفوفة من القيم عن طريق استخراج قيم خاصيةٍ مسمَّاة من كائن آخر.
  
افترض في المثال التالي أن الكائن <code>site.pages</code> يحتوي على جميع البيانات الوصفية metadata لموقع ويب. يؤدي استخدام الوسم <code>assign</code> مع المرشّح <code>map</code> إلى إنشاء متغير يحتوي فقط على قيم خصائص الفئة <code>category</code> لكل شيء في الكائن <code>site.pages</code>.
+
افترض في المثال التالي أن الكائن <code>site.pages</code> يحتوي على جميع البيانات الوصفية metadata لموقع ويب. يؤدي استخدام الوسم <code>assign</code> مع المرشّح <code>map</code> إلى إنشاء متغير يحتوي فقط على قيم خصائص الفئة <code>category</code> لكل شيء في الكائن <code>site.pages</code>.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign all_categories = site.pages | map: "category" %}
 
{% assign all_categories = site.pages | map: "category" %}
  
سطر 608: سطر 346:
 
- {{ item }}
 
- {{ item }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
- business
 
- business
 
- celebrities
 
- celebrities
سطر 616: سطر 353:
 
- technology
 
- technology
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>minus</code> ==
 
== <code>minus</code> ==
يطرح عددًا من عدد آخر.
+
يطرح عددًا من عدد آخر.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 4 | minus: 2 }}
 
{{ 4 | minus: 2 }}
 
{{ 16 | minus: 4 }}
 
{{ 16 | minus: 4 }}
 
{{ 183.357 | minus: 12 }}
 
{{ 183.357 | minus: 12 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
2
 
2
 
12
 
12
 
171.357
 
171.357
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>modulo</code> ==
 
== <code>modulo</code> ==
يعيد هذا المرشّح الباقي من عملية قسمة.
+
يعيد هذا المرشّح الباقي من عملية قسمة.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 3 | modulo: 2 }}
 
{{ 3 | modulo: 2 }}
 
{{ 24 | modulo: 7 }}
 
{{ 24 | modulo: 7 }}
 
{{ 183.357 | modulo: 12 }}
 
{{ 183.357 | modulo: 12 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
1
 
1
 
3
 
3
 
3.357
 
3.357
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>newline_to_br</code> ==
 
== <code>newline_to_br</code> ==
يدخل هذا المرشّح الفاصل السطري (<code><nowiki><br /‎></nowiki></code>) الخاص بلغة HTML أمام كل سطر جديد (<code>‎\n</code>) في سلسلة نصية.
+
يدخل هذا المرشّح الفاصل السطري (<code><nowiki><br /‎></nowiki></code>) الخاص بلغة HTML أمام كل سطر جديد (<code>‎\n</code>) في سلسلة نصية.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% capture string_with_newlines %}
 
{% capture string_with_newlines %}
 
Hello
 
Hello
سطر 667: سطر 384:
  
 
{{ string_with_newlines | newline_to_br }}
 
{{ string_with_newlines | newline_to_br }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
+
 
  
 
<br />
 
<br />
سطر 674: سطر 391:
 
there<br />
 
there<br />
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>plus</code> ==
 
== <code>plus</code> ==
يجمع هذا المرشّح عددين.
+
يجمع هذا المرشّح عددين.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 4 | plus: 2 }}
 
{{ 4 | plus: 2 }}
 
{{ 16 | plus: 4 }}
 
{{ 16 | plus: 4 }}
 
{{ 183.357 | plus: 12 }}
 
{{ 183.357 | plus: 12 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
6
 
6
 
20
 
20
 
195.357
 
195.357
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>prepend</code> ==
 
== <code>prepend</code> ==
يضيف هذا المرشّح سلسلة نصية محدَّدة إلى بداية سلسلة نصية أخرى.
+
يضيف هذا المرشّح سلسلة نصية محدَّدة إلى بداية سلسلة نصية أخرى.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
 
{{ "apples, oranges, and bananas" | prepend: "Some fruit: " }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
Some fruit: apples, oranges, and bananas
 
Some fruit: apples, oranges, and bananas
</syntaxhighlight>
+
</syntaxhighlight>يمكن أن يقبل المرشّح <code>prepend</code> أيضًا متغيرًا كوسيطٍ له.<syntaxhighlight lang="liquid">
|}
 
يمكن أن يقبل المرشّح <code>prepend</code> أيضًا متغيرًا كوسيطٍ له.
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign url = "example.com" %}
 
{% assign url = "example.com" %}
 
{{ "/index.html" | prepend: url }}
 
{{ "/index.html" | prepend: url }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
  
 
example.com/index.html
 
example.com/index.html
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>remove</code> ==
 
== <code>remove</code> ==
يزيل كل ظهور لسلسلة نصية فرعية محدَّدة من سلسلة نصية.
+
يزيل كل ظهور لسلسلة نصية فرعية محدَّدة من سلسلة نصية.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "I strained to see the train through the rain" | remove: "rain" }}
 
{{ "I strained to see the train through the rain" | remove: "rain" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
I sted to see the t through the  
 
I sted to see the t through the  
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>remove_first</code> ==
 
== <code>remove_first</code> ==
يزيل الظهور الأول فقط لسلسلة نصية فرعية محدَّدة من سلسلة نصية.
+
يزيل الظهور الأول فقط لسلسلة نصية فرعية محدَّدة من سلسلة نصية.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "I strained to see the train through the rain" | remove_first: "rain" }}
 
{{ "I strained to see the train through the rain" | remove_first: "rain" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
I sted to see the train through the rain
 
I sted to see the train through the rain
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>replace</code> ==
 
== <code>replace</code> ==
يستبدل هذا المرشّح كلَّ ظهور لوسيطه الأول في سلسلة نصية بوسيطه الثاني.
+
يستبدل هذا المرشّح كلَّ ظهور لوسيطه الأول في سلسلة نصية بوسيطه الثاني.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
 
{{ "Take my protein pills and put my helmet on" | replace: "my", "your" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
Take your protein pills and put your helmet on
 
Take your protein pills and put your helmet on
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>replace_first</code> ==
 
== <code>replace_first</code> ==
يستبدل الظهور الأول فقط لوسيطه الأول في سلسلة نصية بوسيطه الثاني.
+
يستبدل الظهور الأول فقط لوسيطه الأول في سلسلة نصية بوسيطه الثاني.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
 
{{ "Take my protein pills and put my helmet on" | replace_first: "my", "your" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
Take your protein pills and put my helmet on
 
Take your protein pills and put my helmet on
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>reverse</code> ==
 
== <code>reverse</code> ==
يعكس هذا المرشّح ترتيب العناصر في مصفوفة، ولكن لا يمكنه عكس سلسلة نصية.
+
يعكس هذا المرشّح ترتيب العناصر في مصفوفة، ولكن لا يمكنه عكس سلسلة نصية.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
 
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
  
 
{{ my_array | reverse | join: ", " }}
 
{{ my_array | reverse | join: ", " }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
+
 
  
 
plums, peaches, oranges, apples
 
plums, peaches, oranges, apples
</syntaxhighlight>
+
</syntaxhighlight>لا يمكن استخدام المرشّح <code>reverse</code> مع سلسلة نصية مباشرةً، ولكن يمكنك تقسيم split السلسلة إلى مصفوفة، ثم عكس المصفوفة، وإعادة ضمها عن طريق ربط المرشّحات معًا كما يلي:<syntaxhighlight lang="liquid">
|}
 
لا يمكن استخدام المرشّح <code>reverse</code> مع سلسلة نصية مباشرةً، ولكن يمكنك تقسيم split السلسلة إلى مصفوفة، ثم عكس المصفوفة، وإعادة ضمها عن طريق ربط المرشّحات معًا كما يلي:
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}
 
{{ "Ground control to Major Tom." | split: "" | reverse | join: "" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
.moT rojaM ot lortnoc dnuorG
 
.moT rojaM ot lortnoc dnuorG
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>round</code> ==
 
== <code>round</code> ==
يُستخدَم لتقريب عدد إلى أقرب عدد صحيح أو إلى العدد المُمرَّر كوسيط الذي يمثل عدد المنازل العشرية.
+
يُستخدَم لتقريب عدد إلى أقرب عدد صحيح أو إلى العدد المُمرَّر كوسيط الذي يمثل عدد المنازل العشرية.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 1.2 | round }}
 
{{ 1.2 | round }}
 
{{ 2.7 | round }}
 
{{ 2.7 | round }}
 
{{ 183.357 | round: 2 }}
 
{{ 183.357 | round: 2 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
1
 
1
 
3
 
3
 
183.36
 
183.36
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>rstrip</code> ==
 
== <code>rstrip</code> ==
يزيل كل المسافات (مسافات tab والمسافات الفارغة والأسطر الجديدة) من جانب السلسلة الأيمن، ولا يؤثر على المسافات بين الكلمات.
+
يزيل كل المسافات (مسافات tab والمسافات الفارغة والأسطر الجديدة) من جانب السلسلة الأيمن، ولا يؤثر على المسافات بين الكلمات.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "          So much room for activities          " | rstrip }}!
 
{{ "          So much room for activities          " | rstrip }}!
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
           So much room for activities!
 
           So much room for activities!
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>size</code> ==
 
== <code>size</code> ==
يعيد هذا المرشّح عدد المحارف في سلسلة نصية أو عدد العناصر في مصفوفة.
+
يعيد هذا المرشّح عدد المحارف في سلسلة نصية أو عدد العناصر في مصفوفة.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Ground control to Major Tom." | size }}
 
{{ "Ground control to Major Tom." | size }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
 
 
28
 
28
</syntaxhighlight>
+
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
|}
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
 
{% assign my_array = "apples, oranges, peaches, plums" | split: ", " %}
  
 
{{ my_array.size }}
 
{{ my_array.size }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
 +
4
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
<code>4</code>
 
|}
 
 
يمكنك استخدام المرشّح <code>size</code> مع الصيغة النقطية عندما تحتاج إلى استخدام هذا المرشَح ضمن وسم كما يلي:<syntaxhighlight lang="liquid">
 
يمكنك استخدام المرشّح <code>size</code> مع الصيغة النقطية عندما تحتاج إلى استخدام هذا المرشَح ضمن وسم كما يلي:<syntaxhighlight lang="liquid">
 
{% if site.pages.size > 10 %}
 
{% if site.pages.size > 10 %}
سطر 874: سطر 500:
 
يعيد هذا المرشّح سلسلة نصية فرعية مؤلفة من محرف واحد أو يعيد سلسلة من عناصر المصفوفة التي تبدأ بالفهرس المحدَّد باستخدام الوسيط الأول. يحدّد الوسيط الثاني الاختياري طول السلسلة الفرعية أو عدد عناصر المصفوفة المُعادة.
 
يعيد هذا المرشّح سلسلة نصية فرعية مؤلفة من محرف واحد أو يعيد سلسلة من عناصر المصفوفة التي تبدأ بالفهرس المحدَّد باستخدام الوسيط الأول. يحدّد الوسيط الثاني الاختياري طول السلسلة الفرعية أو عدد عناصر المصفوفة المُعادة.
  
تٌرقَّم فهارس السلسلة النصية أو المصفوفة بدءًا من الصفر 0.
+
تٌرقَّم فهارس السلسلة النصية أو المصفوفة بدءًا من الصفر 0.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Liquid" | slice: 0 }}
 
{{ "Liquid" | slice: 0 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <code>L</code>
+
L
|}
+
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Liquid" | slice: 2 }}
 
{{ "Liquid" | slice: 2 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <code>q</code>
+
q
|}
+
</syntaxhighlight>ومثال آخر:<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Liquid" | slice: 2, 5 }}
 
{{ "Liquid" | slice: 2, 5 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <code>quid</code>
+
quid
|}
+
</syntaxhighlight>قيمة الدخل عبارة عن مصفوفة في المثال التالي:<syntaxhighlight lang="liquid">
قيمة الدخل عبارة عن مصفوفة في المثال التالي:
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
 
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
 
{{ beatles | slice: 1, 2 }}
 
{{ beatles | slice: 1, 2 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
<code>PaulGeorge</code>
+
 
|}
+
PaulGeorge
إذا كان الوسيط الأول عبارة عن عدد سالب، تُحسَب الفهارس من نهاية السلسلة النصية.
+
</syntaxhighlight>إذا كان الوسيط الأول عبارة عن عدد سالب، تُحسَب الفهارس من نهاية السلسلة النصية.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Liquid" | slice: -3, 2 }}
 
{{ "Liquid" | slice: -3, 2 }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
ui
 
</syntaxhighlight>
 
</syntaxhighlight>
| <code>ui</code>
 
|}
 
  
 
== <code>sort</code> ==
 
== <code>sort</code> ==
يرتب هذا المرشّح عناصر المصفوفة بترتيب حسّاس لحالة الأحرف.
+
يرتب هذا المرشّح عناصر المصفوفة بترتيب حسّاس لحالة الأحرف.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
 
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
  
 
{{ my_array | sort | join: ", " }}
 
{{ my_array | sort | join: ", " }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
 +
Sally Snake, giraffe, octopus, zebra
 
</syntaxhighlight>
 
</syntaxhighlight>
|  <code>Sally Snake, giraffe, octopus, zebra</code>
 
|}
 
 
يحدّد الوسيط الاختياري خاصيةً من عناصر المصفوفة لاستخدامها في عملية الترتيب.<syntaxhighlight lang="liquid">
 
يحدّد الوسيط الاختياري خاصيةً من عناصر المصفوفة لاستخدامها في عملية الترتيب.<syntaxhighlight lang="liquid">
 
{% assign products_by_price = collection.products | sort: "price" %}
 
{% assign products_by_price = collection.products | sort: "price" %}
سطر 945: سطر 542:
  
 
== <code>sort_natural</code> (خاص بالإصدار 4.0.0) ==
 
== <code>sort_natural</code> (خاص بالإصدار 4.0.0) ==
يرتب العناصر في مصفوفة بترتيب غير حساس لحالة الأحرف.
+
يرتب العناصر في مصفوفة بترتيب غير حساس لحالة الأحرف.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
 
{% assign my_array = "zebra, octopus, giraffe, Sally Snake" | split: ", " %}
  
 
{{ my_array | sort_natural | join: ", " }}
 
{{ my_array | sort_natural | join: ", " }}
 +
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
 +
 +
 +
giraffe, octopus, Sally Snake, zebra
 
</syntaxhighlight>
 
</syntaxhighlight>
|  <code>giraffe, octopus, Sally Snake, zebra</code>
 
|}
 
 
يحدّد الوسيط الاختياري خاصيةً من عناصر المصفوفة لاستخدامها في عملية الترتيب.<syntaxhighlight lang="liquid">
 
يحدّد الوسيط الاختياري خاصيةً من عناصر المصفوفة لاستخدامها في عملية الترتيب.<syntaxhighlight lang="liquid">
 
{% assign products_by_company = collection.products | sort_natural: "company" %}
 
{% assign products_by_company = collection.products | sort_natural: "company" %}
سطر 965: سطر 559:
  
 
== <code>split</code> ==
 
== <code>split</code> ==
يقسم هذا المرشّح سلسلة نصية إلى مصفوفة باستخدام وسيطه كفاصل بين العناصر، حيث يُستخدَم المرشّح <code>split</code> لتحويل العناصر المفصول بينها بفواصل من سلسلة نصية إلى مصفوفة.
+
يقسم هذا المرشّح سلسلة نصية إلى مصفوفة باستخدام وسيطه كفاصل بين العناصر، حيث يُستخدَم المرشّح <code>split</code> لتحويل العناصر المفصول بينها بفواصل من سلسلة نصية إلى مصفوفة.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
 
{% assign beatles = "John, Paul, George, Ringo" | split: ", " %}
  
سطر 976: سطر 565:
 
   {{ member }}
 
   {{ member }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
  
  
سطر 988: سطر 576:
  
 
   Ringo
 
   Ringo
 +
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>strip</code> ==
 
== <code>strip</code> ==
يزيل هذا المرشّح كل المسافات (مسافات tabs والمسافات الفارغة والأسطر الجديدة) من جانبي السلسلة النصية الأيسر والأيمن، ولا يؤثر على المسافات بين الكلمات.
+
يزيل هذا المرشّح كل المسافات (مسافات tabs والمسافات الفارغة والأسطر الجديدة) من جانبي السلسلة النصية الأيسر والأيمن، ولا يؤثر على المسافات بين الكلمات.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "          So much room for activities          " | strip }}!
 
{{ "          So much room for activities          " | strip }}!
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
So much room for activities!
 
So much room for activities!
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>strip_html</code> ==
 
== <code>strip_html</code> ==
يزيل وسوم لغة HTML من سلسلة نصية.
+
يزيل وسوم لغة HTML من سلسلة نصية.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}
 
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
Have you read Ulysses?
 
Have you read Ulysses?
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>strip_newlines</code> ==
 
== <code>strip_newlines</code> ==
يزيل محارف الأسطر الجديدة (فواصل الأسطر) من سلسلة نصية.
+
يزيل محارف الأسطر الجديدة (فواصل الأسطر) من سلسلة نصية.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% capture string_with_newlines %}
 
{% capture string_with_newlines %}
 
Hello
 
Hello
سطر 1٬032: سطر 601:
  
 
{{ string_with_newlines | strip_newlines }}
 
{{ string_with_newlines | strip_newlines }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
+
 
 +
 
 
Hellothere
 
Hellothere
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>times</code> ==
 
== <code>times</code> ==
يضرب عددًا بعدد آخر.
+
يضرب عددًا بعدد آخر.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ 3 | times: 2 }}
 
{{ 3 | times: 2 }}
 
{{ 24 | times: 7 }}
 
{{ 24 | times: 7 }}
 
{{ 183.357 | times: 12 }}
 
{{ 183.357 | times: 12 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
6
 
6
 
168
 
168
 
2200.284
 
2200.284
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>truncate</code> ==
 
== <code>truncate</code> ==
يقتطع سلسلة نصية وصولًا إلى عدد المحارف الذي مُرِّر كوسيط. إذا كان عدد المحارف المحدَّد أقل من طول السلسلة، فستُلحَق علامة القطع ellipsis (...) بالسلسلة النصية وتُضمَّن في عدد المحارف.
+
يقتطع سلسلة نصية وصولًا إلى عدد المحارف الذي مُرِّر كوسيط. إذا كان عدد المحارف المحدَّد أقل من طول السلسلة، فستُلحَق علامة القطع ellipsis (...) بالسلسلة النصية وتُضمَّن في عدد المحارف.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Ground control to Major Tom." | truncate: 20 }}
 
{{ "Ground control to Major Tom." | truncate: 20 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
Ground control to...
 
Ground control to...
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
=== علامات القطع المخصصة ===
 
=== علامات القطع المخصصة ===
 
يأخذ المرشّح <code>truncate</code> وسيطًا ثانيًا اختياريًا يحدّد سلسلة المحارف المراد إلحاقها بالسلسلة المقتطَعة. علامة القطع هي (...) افتراضيًا، ولكن يمكنك تحديد سلسلة مختلفة.
 
يأخذ المرشّح <code>truncate</code> وسيطًا ثانيًا اختياريًا يحدّد سلسلة المحارف المراد إلحاقها بالسلسلة المقتطَعة. علامة القطع هي (...) افتراضيًا، ولكن يمكنك تحديد سلسلة مختلفة.
  
يُحسَب طول الوسيط الثاني مع عدد المحارف المحدَّد بواسطة الوسيط الأول، فإذا أردت اقتطاع سلسلة نصية إلى 10 محارف بالضبط مع استخدام علامة القطع المكونة من 3 محارف مثلًا، فاستخدم القيمة 13 لوسيط المرشّح <code>truncate</code> الأول، لأن علامة القطع تُعَد 3 محارف.
+
يُحسَب طول الوسيط الثاني مع عدد المحارف المحدَّد بواسطة الوسيط الأول، فإذا أردت اقتطاع سلسلة نصية إلى 10 محارف بالضبط مع استخدام علامة القطع المكونة من 3 محارف مثلًا، فاستخدم القيمة 13 لوسيط المرشّح <code>truncate</code> الأول، لأن علامة القطع تُعَد 3 محارف.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
 
{{ "Ground control to Major Tom." | truncate: 25, ", and so on" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
Ground control, and so on
 
Ground control, and so on
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
=== استخدام المرشح truncate بدون علامات القطع ===
 
=== استخدام المرشح truncate بدون علامات القطع ===
يمكنك اقتطاع سلسلة نصية إلى عدد المحارف المحدَّد بواسطة الوسيط الأول، مع تجنّب إظهار المحارف اللاحقة من خلال تمرير سلسلة نصية فارغة كوسيط ثانٍ.
+
يمكنك اقتطاع سلسلة نصية إلى عدد المحارف المحدَّد بواسطة الوسيط الأول، مع تجنّب إظهار المحارف اللاحقة من خلال تمرير سلسلة نصية فارغة كوسيط ثانٍ.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Ground control to Major Tom." | truncate: 20, "" }}
 
{{ "Ground control to Major Tom." | truncate: 20, "" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
Ground control to Ma
 
Ground control to Ma
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>truncatewords</code> ==
 
== <code>truncatewords</code> ==
يقصّر هذا المرشّح من طول السلسلة النصية وصولًا إلى عدد الكلمات الممرَّرة كوسيط. إذا كان عدد الكلمات المحدَّد أقل من عدد الكلمات في السلسلة النصية، فستُلحَق علامة القطع (...) بالسلسلة النصية.
+
يقصّر هذا المرشّح من طول السلسلة النصية وصولًا إلى عدد الكلمات الممرَّرة كوسيط. إذا كان عدد الكلمات المحدَّد أقل من عدد الكلمات في السلسلة النصية، فستُلحَق علامة القطع (...) بالسلسلة النصية.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Ground control to Major Tom." | truncatewords: 3 }}
 
{{ "Ground control to Major Tom." | truncatewords: 3 }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
Ground control to...
 
Ground control to...
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
=== علامات القطع المخصصة ===
 
=== علامات القطع المخصصة ===
يأخذ المرشّح <code>truncatewords</code> وسيطًا ثانيًا اختياريًا يحدّد سلسلة المحارف المراد إلحاقها بالسلسلة المقتطَعة. علامة القطع هي (...) افتراضيًا، ولكن يمكنك تحديد سلسلة مختلفة.
+
يأخذ المرشّح <code>truncatewords</code> وسيطًا ثانيًا اختياريًا يحدّد سلسلة المحارف المراد إلحاقها بالسلسلة المقتطَعة. علامة القطع هي (...) افتراضيًا، ولكن يمكنك تحديد سلسلة مختلفة.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}
 
{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
Ground control to--
 
Ground control to--
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
=== استخدام المرشح truncatewords بدون علامات القطع ===
 
=== استخدام المرشح truncatewords بدون علامات القطع ===
يمكنك تجنّب إظهار المحارف اللاحقة من خلال تمرير سلسلة نصية فارغة كوسيط ثانٍ.
+
يمكنك تجنّب إظهار المحارف اللاحقة من خلال تمرير سلسلة نصية فارغة كوسيط ثانٍ.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Ground control to Major Tom." | truncatewords: 3, "" }}
 
{{ "Ground control to Major Tom." | truncatewords: 3, "" }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
Ground control to
 
Ground control to
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>uniq</code> ==
 
== <code>uniq</code> ==
يزيل العناصر المكرَّرة في المصفوفة.
+
يزيل العناصر المكرَّرة في المصفوفة.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}
 
{% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %}
  
 
{{ my_array | uniq | join: ", " }}
 
{{ my_array | uniq | join: ", " }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
+
 
 +
 
 
ants, bugs, bees
 
ants, bugs, bees
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>upcase</code> ==
 
== <code>upcase</code> ==
يجعل هذا المرشّح كل حرف في السلسلة النصية حرفًا كبيرًا، وليس له أي تأثير على السلاسل النصية التي تتكوّن كلها من أحرف كبيرة مسبقًا.
+
يجعل هذا المرشّح كل حرف في السلسلة النصية باللغة الإنجليزية حرفًا كبيرًا، وليس له أي تأثير على السلاسل النصية التي تتكوّن كلها من أحرف كبيرة مسبقًا.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Parker Moore" | upcase }}
 
{{ "Parker Moore" | upcase }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
PARKER MOORE
 
PARKER MOORE
</syntaxhighlight>
+
</syntaxhighlight>إليك مثال آخر:<syntaxhighlight lang="liquid">
|}
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "APPLE" | upcase }}
 
{{ "APPLE" | upcase }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
APPLE
 
APPLE
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>url_decode</code> (خاص بالإصدار 4.0.0) ==
 
== <code>url_decode</code> (خاص بالإصدار 4.0.0) ==
يفك هذا المرشّح تشفير سلسلة نصية مُشفَّرة كعنوان URL أو مُشفَّرة باستخدام المرشّح <code>url_encode</code>.
+
يفك هذا المرشّح تشفير سلسلة نصية مُشفَّرة كعنوان URL أو مُشفَّرة باستخدام المرشّح <code>url_encode</code>.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "%27Stop%21%27+said+Fred" | url_decode }}
 
{{ "%27Stop%21%27+said+Fred" | url_decode }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
'Stop!' said Fred
 
'Stop!' said Fred
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>url_encode</code> ==
 
== <code>url_encode</code> ==
يحوّل محارف عنوان URL غير آمن في سلسلة نصية إلى محارف مُشفَّرة كنسبة مئوية.
+
يحوّل محارف عنوان URL غير آمن في سلسلة نصية إلى محارف مُشفَّرة كنسبة مئوية.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "john@liquid.com" | url_encode }}
 
{{ "john@liquid.com" | url_encode }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
john%40liquid.com
 
john%40liquid.com
</syntaxhighlight>
+
</syntaxhighlight>لاحظ أن المرشّح <code>url_encode</code> سيحول المسافة إلى إشارة <code>+</code> بدلًا من استخدام محرف النسبة المئوية المُشفَّر.<syntaxhighlight lang="liquid">
|}
 
لاحظ أن المرشّح <code>url_encode</code> سيحول المسافة إلى إشارة <code>+</code> بدلًا من استخدام محرف النسبة المئوية المُشفَّر.
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{{ "Tetsuro Takara" | url_encode }}
 
{{ "Tetsuro Takara" | url_encode }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
Tetsuro+Takara
 
Tetsuro+Takara
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== <code>where</code> (خاص بالإصدار 4.0.2) ==
 
== <code>where</code> (خاص بالإصدار 4.0.2) ==
 
ينشئ هذا المرشّح مصفوفة تتضمن فقط الكائنات التي تملك قيمة خاصية معينة، أو أي قيمة صحيحة [[Liquid/truthy-and-falsy|truthy]] افتراضيًا.
 
ينشئ هذا المرشّح مصفوفة تتضمن فقط الكائنات التي تملك قيمة خاصية معينة، أو أي قيمة صحيحة [[Liquid/truthy-and-falsy|truthy]] افتراضيًا.
  
افترض في المثال التالي أن لديك قائمة بالمنتجات وتريد عرض منتجات مطبخك منفصلة عن بعضها البعض. يمكنك باستخدام المرشّح <code>where</code> إنشاء مصفوفة تحتوي فقط على المنتجات التي لها النوع <code>"type"</code> مطبخ <code>"kitchen"</code>.
+
افترض في المثال التالي أن لديك قائمة بالمنتجات وتريد عرض منتجات مطبخك منفصلة عن بعضها البعض. يمكنك باستخدام المرشّح <code>where</code> إنشاء مصفوفة تحتوي فقط على المنتجات التي لها النوع <code>"type"</code> مطبخ <code>"kitchen"</code>.<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
All products:
 
All products:
 
{% for product in products %}
 
{% for product in products %}
سطر 1٬243: سطر 717:
 
- {{ product.title }}
 
- {{ product.title }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
All products:
 
All products:
 
- Vacuum
 
- Vacuum
سطر 1٬254: سطر 727:
 
- Spatula
 
- Spatula
 
- Garlic press
 
- Garlic press
</syntaxhighlight>
+
</syntaxhighlight>افترض أن لديك قائمة بالمنتجات وتريد فقط إظهار المنتجات المتاحة للشراء. يمكنك استخدام المرشّح <code>where</code> مع اسم خاصية ولكن بدون قيمة مستهدفة لتضمين جميع المنتجات ذات القيمة الصحيحة truthy وهي <code>"available"</code>.<syntaxhighlight lang="liquid">
|}
 
افترض أن لديك قائمة بالمنتجات وتريد فقط إظهار المنتجات المتاحة للشراء. يمكنك استخدام المرشّح <code>where</code> مع اسم خاصية ولكن بدون قيمة مستهدفة لتضمين جميع المنتجات ذات القيمة الصحيحة truthy وهي <code>"available"</code>.
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
All products:
 
All products:
 
{% for product in products %}
 
{% for product in products %}
سطر 1٬273: سطر 739:
 
- {{ product.title }}
 
- {{ product.title }}
 
{% endfor %}
 
{% endfor %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
All products:
 
All products:
 
- Coffee mug
 
- Coffee mug
سطر 1٬283: سطر 748:
 
- Coffee mug
 
- Coffee mug
 
- Boring sneakers
 
- Boring sneakers
</syntaxhighlight>
+
</syntaxhighlight>يمكن أيضًا استخدام المرشّح <code>where</code> للعثور على كائن في مصفوفة عند دمجه مع المرشّح <code>first</code>. لنفترض مثلًا أنك تريد عرض القميص shirt في مجموعتك الجديدة لفصل الخريف.<syntaxhighlight lang="liquid">
|}
 
يمكن أيضًا استخدام المرشّح <code>where</code> للعثور على كائن في مصفوفة عند دمجه مع المرشّح <code>first</code>. لنفترض مثلًا أنك تريد عرض القميص shirt في مجموعتك الجديدة لفصل الخريف.
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign new_shirt = products | where: "type", "shirt" | first %}
 
{% assign new_shirt = products | where: "type", "shirt" | first %}
  
 
Featured product: {{ new_shirt.title }}
 
Featured product: {{ new_shirt.title }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
| <syntaxhighlight lang="liquid">
 
 
Featured product: Hawaiian print sweater vest
 
Featured product: Hawaiian print sweater vest
 
</syntaxhighlight>
 
</syntaxhighlight>
|}
 
  
 
== مصادر ==
 
== مصادر ==

المراجعة الحالية بتاريخ 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

مصادر