Attributes - Block Attributes
The $attributes
or $a
variables only give you access to data registered in
the blockstudio property. To access information about standard block data
like alignment or typography, simply use the $block
or $b
variables.
Rendering
<h1>The block is aligned: <?php echo $block['align']; ?></h1> <h1>The block is aligned: <?php echo $b['align']; ?></h1>
Copy
<h1>The block is aligned: <?php echo $block['align']; ?></h1>
<h1>The block is aligned: <?php echo $b['align']; ?></h1>
<h1>The block is aligned: {{ block.align }}</h1> <h1>The block is aligned: {{ b.align }}</h1>
Copy
<h1>The block is aligned: {{ block.align }}</h1>
<h1>The block is aligned: {{ b.align }}</h1>
Defaults
If you want to set a default value for a property that is set by WordPress like
align
, you can do so by adding a default
key to the property definition
inside the attributes
key.
{ "$schema": "https://app.blockstudio.dev/schema", "name": "blockstudio/block", "title": "Native Block", "icon": "star-filled", "description": "Native Block.", "supports": { "align": ["left", "center", "right"] }, "attributes": { "align": { "type": "string", "default": "center" } }, "blockstudio": true }
Copy
{
"$schema": "https://app.blockstudio.dev/schema",
"name": "blockstudio/block",
"title": "Native Block",
"icon": "star-filled",
"description": "Native Block.",
"supports": {
"align": ["left", "center", "right"]
},
"attributes": {
"align": {
"type": "string",
"default": "center"
}
},
"blockstudio": true
}