This package helps you create and manage native Gutenberg blocks in your Sage theme. It provides a convenient command to scaffold block files and automatically register them with WordPress.
- Hierarchical Template Selection - Organized two-step selection process with template categories
- Multiple Block Templates - Choose from pre-configured templates for common block patterns
- Dynamic Theme Detection - Automatically discovers and displays theme-specific templates
- Scaffolds a complete native block structure in your Sage theme
- Automatically adds block registration code to your theme's setup file
- Creates all necessary block files (JS, JSX, CSS) with proper configuration
- Handles proper block naming with vendor prefixes
- Creates editor and frontend styles for your blocks
- Ensures proper imports of block JS files
- 80% faster development - Start with pre-configured templates instead of building from scratch
You can install this package with Composer from your Sage 11+ theme root directory (not from the Bedrock root):
composer require imagewize/sage-native-block --devThat's it! The package is ready to use. No additional setup required.
You can drop --dev but then it will be included in your production build.
The package works out of the box with default settings. However, you can optionally publish the config file to customize template settings:
wp acorn vendor:publish --provider="Imagewize\SageNativeBlockPackage\Providers\SageNativeBlockServiceProvider"When to publish:
- You want to customize typography or spacing presets
- You want to add your own template definitions to the config
- You're experiencing config loading issues in your environment (rare)
Note: Since v2.0.1, the package automatically falls back to loading config directly if it's not published, making this step truly optional.
Simply run the command and follow the prompts:
wp acorn sage-native-block:createYou'll be guided through an interactive setup:
- Block name: Enter your block name (e.g., "my-stats")
- Vendor prefix: Optionally specify a vendor (defaults to "vendor")
- Template category: Choose between Basic Block, Generic Templates, or Theme-specific templates
- Template selection: Choose a specific template within your selected category
- Confirmation: Review and confirm your choices
The command will then:
- Create the block in your theme's
resources/js/blocksdirectory - Add block registration code to your theme's
app/setup.phpif not already present - Update
resources/js/editor.jsto import the block files
You can still provide all parameters via CLI arguments:
wp acorn sage-native-block:create my-block --template=statistics --forceThe package provides a clean, professional terminal interface:
π¨ Creating block: imagewize/my-stats
ββββββββββββββββββββββββββββββββββββββββ
Template: Statistics Section (Generic)
Location: resources/js/blocks/my-stats
Continue? (yes/no) [no]: yes
Setup:
β Block registration configured
β Editor imports configured
Files:
β block.json, index.js
β editor.jsx, save.jsx
β editor.css, style.css
β view.js
ββββββββββββββββββββββββββββββββββββββββ
β Success! Block ready at resources/js/blocks/my-stats
Features:
- Clear visual hierarchy with emoji header and separators
- Color-coded output for easy scanning
- Check marks (β) for quick status updates
- Grouped file operations reduce noise
- Relative paths for better readability
The package provides an organized, hierarchical template selection system. When creating a block interactively, you'll first choose a template category, then select a specific template within that category.
The command automatically presents available categories:
- Basic Block - Default simple block (selected directly, no sub-options)
- Generic Templates - Universal, theme-agnostic templates that work everywhere
- Theme Templates - Production-ready templates from specific themes
- Custom Templates - Your own custom templates (auto-detected)
π‘ Custom Templates: Create your own templates without modifying the vendor package!
- Create a folder in your theme:
block-templates/my-template/- Add required files:
block.json,index.js,editor.jsx,save.jsx, etc.- Optional: Add
template-meta.jsonfor custom name, description, and category- Templates automatically appear in the selection menu
- Override package templates by using the same template name
The package includes templates in these categories:
Universal templates that work with ANY theme - no dependencies required:
| Template | Description | Use Case |
|---|---|---|
| basic | Simple block with InnerBlocks support | General-purpose container blocks |
| innerblocks | Minimal heading and content template | Section blocks (add your own styles) |
| two-column | Basic two-column layout structure | Feature comparisons, benefits |
| statistics | Simple statistics layout | Impact metrics, key numbers |
| cta | Basic call-to-action with button | Lead generation, conversions |
Real-world examples from production themes. Currently featuring templates from the Nynaeve theme by Imagewize.
- Font families:
montserrat,open-sans - Color slugs:
main,secondary,tertiary,base - Font sizes:
3xl,2xl,xl,lg,base,sm
| Template | Description | Use Case |
|---|---|---|
| nynaeve-innerblocks | Pre-styled with Nynaeve typography | Production-ready container |
| nynaeve-two-column | Card-style layout from Nynaeve | Polished two-column sections |
| nynaeve-statistics | Complete statistics from Nynaeve | Production-ready stats display |
| nynaeve-cta | Styled CTA from Nynaeve theme | Ready-to-use call-to-action |
π‘ Tip: Use generic templates for universal compatibility, or Nynaeve templates if your theme matches its setup. See
stubs/themes/nynaeve/README.mdfor detailed requirements.
Interactive mode (easiest):
# Follow prompts to create any block
wp acorn sage-native-block:createWith block name (prompts for category and template):
wp acorn sage-native-block:create my-statsWith vendor prefix:
wp acorn sage-native-block:create imagewize/my-statsFully automated (no prompts):
# Generic templates (work everywhere)
wp acorn sage-native-block:create my-stats --template=statistics --force
wp acorn sage-native-block:create my-cta --template=cta --force
wp acorn sage-native-block:create my-columns --template=two-column --force
wp acorn sage-native-block:create my-container --template=innerblocks --force
# Nynaeve theme templates (requires Nynaeve theme.json setup)
wp acorn sage-native-block:create my-stats --template=nynaeve-statistics --force
wp acorn sage-native-block:create imagewize/my-cta --template=nynaeve-cta --forceThe command creates the following files in your resources/js/blocks/<block-name>/ directory:
block.json- Block metadata and configurationindex.js- Main block entry pointeditor.jsx- React component for the editorsave.jsx- React component for the frontendeditor.css- Styles for the block in the editorstyle.css- Styles for the block on the frontendview.js- Frontend JavaScript for the block
The command automatically handles:
- Block naming - Ensures proper vendor prefixes (e.g.,
imagewize/my-block) - CSS classes - Generates block-specific classes (e.g.,
wp-block-imagewize-my-block) - Registration - Adds code to
app/setup.phpto auto-register all blocks - Imports - Updates
resources/js/editor.jsto load block scripts - File structure - Creates organized directory with all 7 required files
Example structure for imagewize/testimonial:
resources/js/blocks/testimonial/
βββ block.json β Block metadata
βββ index.js β Registration entry point
βββ editor.jsx β Edit component
βββ save.jsx β Save component
βββ editor.css β Editor-only styles
βββ style.css β Frontend styles
βββ view.js β Frontend JavaScript
π‘ For technical details on the build process and architecture, see Developer Documentation
Optional: If you want to customize global typography and spacing presets used by package templates, publish the config file:
wp acorn vendor:publish --provider="Imagewize\SageNativeBlockPackage\Providers\SageNativeBlockServiceProvider"Then edit config/sage-native-block.php to match your theme's design system.
Note: This only affects package templates (basic, generic, nynaeve). Your custom templates in block-templates/ are unaffected and use whatever styles you define in them.
Want to create your own block templates? It's incredibly simple - no configuration needed!
-
Create template folder in your Sage theme root:
mkdir -p block-templates/my-hero
-
Add template files (copy from an existing template or create from scratch):
block-templates/my-hero/ βββ block.json βββ index.js βββ editor.jsx βββ save.jsx βββ editor.css βββ style.css βββ view.js -
Run the command - Your template automatically appears in the menu:
wp acorn sage-native-block:create
That's it! No config files, no vendor package modification needed.
For better display names and organization, add template-meta.json:
{
"name": "Hero Section",
"description": "Full-featured hero with background image support",
"category": "custom"
}Metadata fields (all optional):
name- Display name in menu (defaults to folder name)description- Template description (defaults to "Custom template")category- Category name (defaults to "custom")author- Template authorversion- Template version
Create a template with the same name as a package template to override it:
# Override the generic "innerblocks" template
mkdir -p block-templates/innerblocks
# Add your custom files...Your theme's version will be used instead of the package version.
# 1. Copy an existing template as a starting point
cp -r vendor/imagewize/sage-native-block/stubs/generic/innerblocks block-templates/hero
# 2. Customize the files (editor.jsx, save.jsx, etc.)
# 3. Add metadata
cat > block-templates/hero/template-meta.json << 'EOF'
{
"name": "Hero Section",
"description": "Hero with heading, text, and background image",
"category": "layout"
}
EOF
# 4. Use it!
wp acorn sage-native-block:create my-hero --template=heroπ‘ Tip: Check out existing templates in
vendor/imagewize/sage-native-block/stubs/for examples and inspiration.
For advanced template customization, see the Custom Template Stubs Documentation.
your-sage-theme/
βββ block-templates/ β Create this folder
β βββ hero/ β Your custom template
β β βββ block.json
β β βββ index.js
β β βββ editor.jsx
β β βββ save.jsx
β β βββ editor.css
β β βββ style.css
β β βββ view.js
β β βββ template-meta.json β Optional metadata
β βββ cta/ β Another custom template
β β βββ ...
β βββ stats/ β Yet another template
β βββ ...
βββ resources/
β βββ js/
β βββ blocks/ β Generated blocks go here
βββ config/
βββ sage-native-block.php β Optional: published config
Templates in block-templates/ are automatically discovered - no configuration needed!
Have templates from your production theme? We welcome community contributions! Check the Theme Templates Guide for guidelines on contributing theme-specific templates.
- 80% faster development - Start with pre-configured templates instead of building from scratch
- Organized selection - Hierarchical categories make finding the right template easy
- Extensible system - Add your own theme templates with automatic detection
- Consistent patterns - All blocks follow established structure and best practices
- Theme integration - Templates use theme.json values for typography and colors
- Proper InnerBlocks setup - Avoid common mistakes with InnerBlocks configuration
- Reduced errors - Well-tested templates reduce debugging time
- Learning tool - See WordPress block best practices in generated code
See CHANGELOG.md for detailed version history and release notes.