Blockstudio
Blocks

Context

When blocks are used inside a loop (for example, a Query block), the block is executed once for each iteration of the loop. Blockstudio provides handy shortcuts for accessing the current loop and outer context.

index.php
<div>
  <h1>
    This is the data of current
    element inside the loop:
    <?php echo $block['context']['postId'] ?>
    <?php echo $block['context']['postType'] ?>
  </h1>
  <h1>
    This is the data the current post:
    <?php echo $block['postId'] ?>
    <?php echo $block['postType'] ?>
  </h1>
</div>
index.twig
<div>
  <h1>
    This is the data of current
    element inside the loop:
    {{ block.context.postId }}
    {{ block.context.postType }}
  </h1>
  <h1>
    This is the data the current post:
    {{ block.postId }}
    {{ block.postType }}
  </h1>
</div>

Available Variables

Inside your block templates, you have access to these variables:

VariableShorthandDescription
$attributes$aBlock attributes
$block$bBlock data (name, title, postId, postType, context, etc.)
$context$cParent block context
$innerBlocks-InnerBlocks content

Block Data

The $block / $b variable contains:

PropertyDescription
nameBlock name (e.g., my-theme/my-block)
titleBlock title
dirBlock directory path
urlBlock directory URL
postIdCurrent post ID
postTypeCurrent post type
contextLoop context (when inside a Query block)

Parent Context

When using usesContext, access parent block data via $context:

index.php
<?php
$parent = $context['parent-block/name'];
echo $parent['someAttribute'];
?>

Blockstudio handles providesContext automatically. You only need to add usesContext to the child block. There is no need to manually declare providesContext in the parent block's block.json, as Blockstudio registers it for all attributes.

See InnerBlocks Context for more details.

Guide: Block Context and CommunicationPractical patterns: card grids, pricing tables, and section wrappers where blocks need to share data.

On this page