Getting Started
Features
- API
- Blocks
- Blocks with JS
- Helper Classes
- Block Fields
- Accessing Fields
- Text Margin
- Presets
- Block Settings
- Drag & Drop Sortable
- Block Spacings
- Custom Block Stubs
- Widgets
Requirements
PHP>=8.0ProcessWire>=3.0.227RockMigrations>=3.30.0RockFrontend>=3.6.0- API
Custom Block Stubs
Overview
RockPageBuilder allows you to create custom "stub" files for generating new blocks. These stubs serve as boilerplate code, providing a consistent starting point for block creation. By default, the module offers two versions of stubs:
- A commented version for beginners
- An advanced version without comments for experienced users
The Problem
Every website has unique requirements, such as different CSS frameworks (Bootstrap, TailwindCSS, etc.) or project-specific markup. The default stubs may not always align with your project's needs, leading to:
- Time-consuming cleanup and class modifications for each new block
- Potential oversights in adding project-specific classes or structures
- Inconsistencies across blocks, possibly introducing bugs
The Solution: Custom Stubs
To address these issues, RockPageBuilder allows you to create custom stub files tailored to your project's needs.
How to Implement Custom Stubs
- Create a directory:
/site/templates/RockPageBuilder/stubs/
- Add your custom stub files to this directory:
- For PHP files:
.Block.php
(note the leading dot) - For view files:
.Block.latte
or.Block.view.php
- For PHP files:
Example: Custom PHP Stub
Create a file /site/templates/RockPageBuilder/stubs/.Block.php
:
// site/templates/RockPageBuilder/stubs/.Block.php
<?php
namespace RockPageBuilderBlock;
use RockPageBuilder\Block;
class {name} extends Block {
const prefix = "rpb_{namelower}_";
public function info() {
return [
'title' => '{name}',
];
}
public function migrate()
{
$rm = $this->rockmigrations();
$rm->migrate([
'fields' => [],
'templates' => [
$this->getTplName() => [
'fields-' => [],
],
],
]);
}
}
Example: Custom View Stub (Latte)
Create a file /site/templates/RockPageBuilder/stubs/.Block.latte
:
{* site/templates/RockPageBuilder/stubs/.Block.latte *}
<section
class="{cls} tm-block {$site->bgClass}"
{alfred($block)}
>
<div class='uk-container text-auto'>
TBD
</div>
</section>
This example uses UIkit classes and includes a generic tm-block
class and a bgClass
from the global $site
object.
Benefits
By using custom stubs, you can:
- Ensure consistency across all blocks in your project
- Reduce the time spent on initial block setup
- Minimize the risk of forgetting project-specific classes or structures
- Tailor the initial block code to your project's specific needs and coding standards
Remember to adjust these custom stubs as your project evolves to maintain their relevance and effectiveness.