Enregistrement des attributs
Les attributs sont définis dans le tableau blockstudio.attributes de votre fichier block.json.
Exemple de base
JSON
{
"name": "my-theme/my-block",
"title": "My Block",
"blockstudio": {
"attributes": [
{
"id": "title",
"type": "text",
"label": "Title"
},
{
"id": "content",
"type": "textarea",
"label": "Content"
}
]
}
}
Propriétés des attributs
Tous les attributs partagent les propriétés suivantes :
| Propriété | Type | Description |
|---|---|---|
id |
string | Identifiant unique de l’attribut |
type |
string | Type de champ (text, textarea, select, etc.) |
label |
string | Libellé affiché dans l’éditeur |
default |
mixed | Valeur par défaut de l’attribut |
help |
string | Texte d’aide affiché sous forme d’infobulle à côté du libellé |
position |
string | Emplacement du champ : inspector (par défaut) ou toolbar |
conditions |
array | Logique conditionnelle pour afficher ou masquer le champ |
Position
Par défaut, tous les champs s’affichent dans l’inspecteur de blocs (barre latérale). Vous pouvez modifier cela avec la propriété 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" }
]
}
]
}
}
Valeurs par défaut
Définissez les valeurs par défaut avec la propriété default :
JSON
{
"blockstudio": {
"attributes": [
{
"id": "title",
"type": "text",
"label": "Title",
"default": "Hello World"
},
{
"id": "showBorder",
"type": "toggle",
"label": "Show Border",
"default": true
}
]
}
}
Texte d’aide
Ajoutez un texte d’aide pour guider les utilisateurs :
JSON
{
"blockstudio": {
"attributes": [
{
"id": "apiKey",
"type": "text",
"label": "API Key",
"help": "Enter your API key from the settings page"
}
]
}
}
Accès aux attributs
Dans votre modèle, les attributs sont accessibles via le raccourci $a (ou $attributes) :
PHP
<h1><?php echo $a['title']; ?></h1>
<p><?php echo $a['content']; ?></p>
Ou dans Twig :
Twig
<h1>{{ a.title }}</h1>
<p>{{ a.content }}</p>