Attributes - Block attributes

Last modified:

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

index.php
index.twig

          <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: {{ block.align }}</h1>
  <h1>The block is aligned: {{ b.align }}</h1>
Copy

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.

block.json

            {
      "$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