Skip to content

Latest commit

 

History

History
73 lines (51 loc) · 1.81 KB

README.md

File metadata and controls

73 lines (51 loc) · 1.81 KB

Sage Carbon Fields

This is a package to create blocks easily with Carbon Fields in every Sage Wordpress website.

How to use?

Create a package using the console:

wp acorn make:block MyCustonBlock

It will return:

Block [app/Fields/Blocks/MyCustomBlock.php] was created successfully
View [resources/views/blocks/my-custom-block.blade.php] was created successfully

Now just navigate to the Class/view to edit as you wish. Use the Carbon Fields official documentation to learn more how to create fields in your component.

To load the block in your sage template, use in any php file (like setup.php, fitlers.php, or create one - like I do in my templates) and register the block:

use App\Fields\Blocks\MyCustomBlock;

myCustomBlock::register();

Get deep in the Block Class

Here's how edit your new block class:

<?php

namespace App\Fields\Blocks;

use Rmarsigli\SageCarbonFields\Traits\HasBlock;
use Carbon_Fields\Field;

class MyCustomBlock {

	use HasBlock;

	public function name(): string
	{
		return 'MyCustomBlock'; // Name your Block to find it in the WordPress editor
	}

	public function fields(): array
	{
		return [
			Field::make('text', 'rwp_name', __('Name', 'sage')), // Use the Carbon Fields here, check their docs
		];
	}

	public function category(): array|string
	{
		return ['rafha-wp', 'Rafha WP', 'wordpress']; // Slug, Name and dash-icon of the block, you can only use string to use default variables
	}

	public function view(): string
	{
		return 'blocks.my-custom-block'; // Name of the view inside views folder
	}

	public function innerBlocks(): bool
	{
		return false; // Set to true to enable inner blocks inside this block
	}
}