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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
ط (مراجعة)
 
سطر 1: سطر 1:
== التحكم بالمسافات Whitespace ==
+
<noinclude>{{DISPLAYTITLE: التحكم بالمسافات الفارغة Whitespace في Liquid}}</noinclude>
 
يمكنك في لغة Liquid تضمين شرطة (-) في صيغة الوسم tag كما يلي: <code><nowiki>{{-</nowiki></code> و <code><nowiki>-}}</nowiki></code> و <code>{%-</code> و <code>-%}</code> لحذف المسافة من جانب الوسم المصيَّر rendered tag الأيسر أو الأيمن.
 
يمكنك في لغة Liquid تضمين شرطة (-) في صيغة الوسم tag كما يلي: <code><nowiki>{{-</nowiki></code> و <code><nowiki>-}}</nowiki></code> و <code>{%-</code> و <code>-%}</code> لحذف المسافة من جانب الوسم المصيَّر rendered tag الأيسر أو الأيمن.
  
سيطبع أي سطر من شيفرة Liquid في القالب سطرًا فارغًا ضمن ملف HTML المصيَّر حتى إن لم يطبع نصًا:
+
يُحوَّل أي سطر من شيفرة Liquid في القالب إلى سطر إضافي ضمن ملف HTML المصيَّر حتى إن لم يحتوي ذلك السطر على نص لطباعته فيه:<syntaxhighlight lang="liquid">
{| class="wikitable"
 
|+
 
!الدخل
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign my_variable = "tomato" %}
 
{% assign my_variable = "tomato" %}
 
{{ my_variable }}
 
{{ my_variable }}
</syntaxhighlight>
+
</syntaxhighlight>لاحظ السطر الفارغ قبل كلمة "tomato" في القالب المصيَّر:<syntaxhighlight lang="liquid">
|}
+
لاحظ السطر الفارغ قبل كلمة "tomato" في القالب المصيَّر:
+
tomato
{| class="wikitable"
+
</syntaxhighlight>لكن إذا ضمّنت شرطة في محدّد إغلاق الوسم <code>assign</code>، فيمكنك حذف المسافة التي تليه من القالب المصيَّر:<syntaxhighlight lang="liquid">
!الخرج
 
|-
 
|<code> </code>
 
 
 
<code>tomato</code>
 
|}
 
لكن إذا ضمّنت شرطة في محدّد إغلاق الوسم <code>assign</code>، فيمكنك حذف المسافة التي تليه من القالب المصيَّر:
 
{| class="wikitable"
 
!الدخل
 
!الخرج
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign my_variable = "tomato" -%}
 
{% assign my_variable = "tomato" -%}
 
{{ my_variable }}
 
{{ my_variable }}
</syntaxhighlight>
+
</syntaxhighlight>الخرج:<syntaxhighlight lang="liquid">
|<code>tomato</code>
+
tomato
|}
+
</syntaxhighlight>إن لم ترِد أن تطبع وسومك أيّ مسافات فارغة، فيمكنك إضافة شرطات إلى جانبي كل الوسمين <code>{%-</code> و <code>-%}</code>:<syntaxhighlight lang="liquid">
إن لم ترِد أن تطبع وسومك أيّ مسافة، فيمكنك إضافة شرطات إلى جانبي كل الوسمين <code>{%-</code> و <code>-%}</code>:
 
{| class="wikitable"
 
!الدخل
 
!الخرج دون التحكم بالمسافات
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign username = "John G. Chalmers-Smith" %}
 
{% assign username = "John G. Chalmers-Smith" %}
 
{% if username and username.size > 10 %}
 
{% if username and username.size > 10 %}
سطر 43: سطر 20:
 
   Hello there!
 
   Hello there!
 
{% endif %}
 
{% endif %}
</syntaxhighlight>
+
</syntaxhighlight>الخرج دون التحكم بالمسافات الفارغة:<syntaxhighlight lang="liquid">
|<syntaxhighlight lang="liquid">
+
 
+
 
 
 
   Wow, John G. Chalmers-Smith , you have a long name!
 
   Wow, John G. Chalmers-Smith , you have a long name!
</syntaxhighlight>
+
                  ‏
|}
+
</syntaxhighlight>أما في المثال التالي:<syntaxhighlight lang="liquid">
{| class="wikitable"
 
!الدخل
 
!الخرج مع التحكم بالمسافات
 
|-
 
|<syntaxhighlight lang="liquid">
 
 
{% assign username = "John G. Chalmers-Smith" -%}
 
{% assign username = "John G. Chalmers-Smith" -%}
 
{%- if username and username.size > 10 -%}
 
{%- if username and username.size > 10 -%}
سطر 61: سطر 32:
 
   Hello there!
 
   Hello there!
 
{%- endif %}
 
{%- endif %}
 +
</syntaxhighlight>يكون الخرج مع التحكم بالمسافات:<syntaxhighlight lang="liquid">
 +
Wow, John G. Chalmers-Smith, you have a long name!
 
</syntaxhighlight>
 
</syntaxhighlight>
|<code>Wow, John G. Chalmers-Smith, you have a long name!‎</code>
 
|}
 
 
== مصادر ==
 
== مصادر ==
  
 
* [https://shopify.github.io/liquid/basics/whitespace/ صفحة Whitespace control في توثيق Liquid الرسمي.]
 
* [https://shopify.github.io/liquid/basics/whitespace/ صفحة Whitespace control في توثيق Liquid الرسمي.]
 +
[[تصنيف:Liquid]]

المراجعة الحالية بتاريخ 11:36، 5 أغسطس 2021

يمكنك في لغة Liquid تضمين شرطة (-) في صيغة الوسم tag كما يلي: {{- و -}} و {%- و -%} لحذف المسافة من جانب الوسم المصيَّر rendered tag الأيسر أو الأيمن.

يُحوَّل أي سطر من شيفرة Liquid في القالب إلى سطر إضافي ضمن ملف HTML المصيَّر حتى إن لم يحتوي ذلك السطر على نص لطباعته فيه:

{% assign my_variable = "tomato" %}
{{ my_variable }}

لاحظ السطر الفارغ قبل كلمة "tomato" في القالب المصيَّر:

 
tomato

لكن إذا ضمّنت شرطة في محدّد إغلاق الوسم assign، فيمكنك حذف المسافة التي تليه من القالب المصيَّر:

{% assign my_variable = "tomato" -%}
{{ my_variable }}

الخرج:

tomato

إن لم ترِد أن تطبع وسومك أيّ مسافات فارغة، فيمكنك إضافة شرطات إلى جانبي كل الوسمين {%- و -%}:

{% assign username = "John G. Chalmers-Smith" %}
{% if username and username.size > 10 %}
  Wow, {{ username }} , you have a long name!
{% else %}
  Hello there!
{% endif %}

الخرج دون التحكم بالمسافات الفارغة:

 
 
  Wow, John G. Chalmers-Smith , you have a long name!
                  ‏

أما في المثال التالي:

{% assign username = "John G. Chalmers-Smith" -%}
{%- if username and username.size > 10 -%}
  Wow, {{ username -}} , you have a long name!
{%- else -%}
  Hello there!
{%- endif %}

يكون الخرج مع التحكم بالمسافات:

Wow, John G. Chalmers-Smith, you have a long name!

مصادر