Blockstudio
BlocksAttributes

Block Attributes

The $attributes or $a variables only give you access to data registered in the blockstudio property. To access standard WordPress block data like alignment or typography, use the $block or $b variables.

Rendering

index.php
<h1>The block is aligned: <?php echo $block['align']; ?></h1>
<h1>The block is aligned: <?php echo $b['align']; ?></h1>
index.twig
<h1>The block is aligned: {{ block.align }}</h1>
<h1>The block is aligned: {{ b.align }}</h1>

Setting Defaults

To set a default value for WordPress properties like align, add a default key inside the attributes key:

block.json
{
  "$schema": "https://blockstudio.dev/schema/block",
  "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
}

Available Block Data

The $block / $b variable contains:

PropertyDescription
nameBlock name (e.g., my-theme/my-block)
titleBlock title
dirBlock directory path
urlBlock directory URL
alignAlignment value (if supports.align is enabled)
classNameCustom CSS class (if supports.customClassName is enabled)
anchorHTML anchor/ID (if supports.anchor is enabled)

WordPress Supports

Enable WordPress block features via the supports property:

block.json
{
  "supports": {
    "align": true,
    "anchor": true,
    "customClassName": true,
    "color": {
      "background": true,
      "text": true
    },
    "spacing": {
      "margin": true,
      "padding": true
    },
    "typography": {
      "fontSize": true,
      "lineHeight": true
    }
  }
}

See the WordPress Block Supports documentation for all available options.

On this page