تسجيل السمات
تُعرّف السمات ضمن مصفوفة blockstudio.attributes في ملف block.json.
مثال أساسي
JSON
{
"name": "my-theme/my-block",
"title": "My Block",
"blockstudio": {
"attributes": [
{
"id": "title",
"type": "text",
"label": "Title"
},
{
"id": "content",
"type": "textarea",
"label": "Content"
}
]
}
}
خصائص السمات
تشترك جميع السمات في الخصائص التالية:
| الخاصية | النوع | الوصف |
|---|---|---|
id |
string | معرّف فريد للسمة |
type |
string | نوع الحقل (text، textarea، select، إلخ) |
label |
string | التسمية المعروضة في المحرر |
default |
mixed | القيمة الافتراضية للسمة |
help |
string | نص المساعدة المعروض كتلميح بجوار التسمية |
position |
string | موضع ظهور الحقل: inspector (افتراضيًا) أو toolbar |
conditions |
array | منطق شرطي لإظهار الحقل أو إخفائه |
الموضع
افتراضيًا، تظهر جميع الحقول في مفتش الكتلة (الشريط الجانبي). يمكنك تغيير ذلك باستخدام الخاصية position:
JSON
{
"blockstudio": {
"attributes": [
{
"id": "alignment",
"type": "select",
"label": "Alignment",
"position": "toolbar",
"options": [
{ "value": "left", "label": "Left" },
{ "value": "center", "label": "Center" },
{ "value": "right", "label": "Right" }
]
}
]
}
}
القيم الافتراضية
عيّن القيم الافتراضية باستخدام الخاصية default:
JSON
{
"blockstudio": {
"attributes": [
{
"id": "title",
"type": "text",
"label": "Title",
"default": "Hello World"
},
{
"id": "showBorder",
"type": "toggle",
"label": "Show Border",
"default": true
}
]
}
}
نص المساعدة
أضف نصًا إرشاديًا لمساعدة المستخدمين:
JSON
{
"blockstudio": {
"attributes": [
{
"id": "apiKey",
"type": "text",
"label": "API Key",
"help": "Enter your API key from the settings page"
}
]
}
}
الوصول إلى السمات
في القالب، تتوفر السمات عبر الاختصار $a (أو $attributes):
PHP
<h1><?php echo $a['title']; ?></h1>
<p><?php echo $a['content']; ?></p>
أو في Twig:
Twig
<h1>{{ a.title }}</h1>
<p>{{ a.content }}</p>