Attributen registreren
Attributen worden gedefinieerd in de array blockstudio.attributes in uw bestand block.json.
Basisvoorbeeld
JSON
{
"name": "my-theme/my-block",
"title": "My Block",
"blockstudio": {
"attributes": [
{
"id": "title",
"type": "text",
"label": "Title"
},
{
"id": "content",
"type": "textarea",
"label": "Content"
}
]
}
}
Attribuuteigenschappen
Alle attributen hebben de volgende eigenschappen:
| Eigenschap | Type | Beschrijving |
|---|---|---|
id |
string | Unieke identificatie voor het attribuut |
type |
string | Het veldtype (text, textarea, select, enz.) |
label |
string | Label dat in de editor wordt weergegeven |
default |
mixed | Standaardwaarde voor het attribuut |
help |
string | Helptekst die als tooltip naast het label wordt weergegeven |
position |
string | Waar het veld wordt weergegeven: inspector (standaard) of toolbar |
conditions |
array | Voorwaardelijke logica om het veld weer te geven of te verbergen |
Positie
Standaard worden alle velden weergegeven in de blokinspecteur (zijbalk). U kunt dit wijzigen met de eigenschap 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" }
]
}
]
}
}
Standaardwaarden
Stel standaardwaarden in met de eigenschap default:
JSON
{
"blockstudio": {
"attributes": [
{
"id": "title",
"type": "text",
"label": "Title",
"default": "Hello World"
},
{
"id": "showBorder",
"type": "toggle",
"label": "Show Border",
"default": true
}
]
}
}
Helptekst
Voeg helptekst toe om gebruikers te begeleiden:
JSON
{
"blockstudio": {
"attributes": [
{
"id": "apiKey",
"type": "text",
"label": "API Key",
"help": "Enter your API key from the settings page"
}
]
}
}
Attributen openen
In uw template zijn attributen beschikbaar via de verkorte notatie $a (of $attributes):
PHP
<h1><?php echo $a['title']; ?></h1>
<p><?php echo $a['content']; ?></p>
Of in Twig:
Twig
<h1>{{ a.title }}</h1>
<p>{{ a.content }}</p>