Pular para o conteúdo

Registro de atributos

Os atributos são definidos no array blockstudio.attributes do arquivo block.json.

Exemplo básico

JSON
{
  "name": "my-theme/my-block",
  "title": "My Block",
  "blockstudio": {
    "attributes": [
      {
        "id": "title",
        "type": "text",
        "label": "Title"
      },
      {
        "id": "content",
        "type": "textarea",
        "label": "Content"
      }
    ]
  }
}

Propriedades dos atributos

Todos os atributos compartilham as seguintes propriedades:

Propriedade Tipo Descrição
id string Identificador exclusivo do atributo
type string O tipo de campo (text, textarea, select etc.)
label string Rótulo exibido no editor
default mixed Valor padrão do atributo
help string Texto de ajuda exibido como dica de ferramenta ao lado do rótulo
position string Onde o campo aparece: inspector (padrão) ou toolbar
conditions array Lógica condicional para mostrar ou ocultar o campo

Posição

Por padrão, todos os campos são exibidos no inspetor de blocos (barra lateral). Você pode alterar isso usando a propriedade 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" }
        ]
      }
    ]
  }
}

Valores padrão

Defina valores padrão usando a propriedade default:

JSON
{
  "blockstudio": {
    "attributes": [
      {
        "id": "title",
        "type": "text",
        "label": "Title",
        "default": "Hello World"
      },
      {
        "id": "showBorder",
        "type": "toggle",
        "label": "Show Border",
        "default": true
      }
    ]
  }
}

Texto de ajuda

Adicione um texto de ajuda para orientar os usuários:

JSON
{
  "blockstudio": {
    "attributes": [
      {
        "id": "apiKey",
        "type": "text",
        "label": "API Key",
        "help": "Enter your API key from the settings page"
      }
    ]
  }
}

Acesso a atributos

No seu modelo, os atributos estão disponíveis pelo atalho $a (ou $attributes):

PHP
<h1><?php echo $a['title']; ?></h1>
<p><?php echo $a['content']; ?></p>

Ou em Twig:

Twig
<h1>{{ a.title }}</h1>
<p>{{ a.content }}</p>

Receitas de padrões de campos