본문으로 건너뛰기

속성 등록

속성은 block.json 파일의 blockstudio.attributes 배열에서 정의합니다.

기본 예제

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

속성

모든 속성은 다음 속성을 공유합니다.

속성 유형 설명
id string 속성의 고유 식별자
type string 필드 유형(text, textarea, select 등)
label string 편집기에 표시되는 레이블
default mixed 속성의 기본값
help string 레이블 옆 툴팁으로 표시되는 도움말 텍스트
position string 필드 표시 위치: inspector(기본값) 또는 toolbar
conditions array 필드 표시/숨김을 위한 조건부 로직

위치

기본적으로 모든 필드는 블록 검사기(사이드바)에 표시됩니다. 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" }
        ]
      }
    ]
  }
}

기본값

default 속성으로 기본값을 설정하세요.

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

도움말 텍스트

사용자 안내를 위한 도움말 텍스트를 추가하세요.

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

속성 액세스

템플릿에서 $a 축약 표기(또는 $attributes)로 속성에 액세스할 수 있습니다.

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

또는 Twig에서:

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

필드 패턴 요리책