1. Go to this page and download the library: Download idetik/coretik-page-builder library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
idetik / coretik-page-builder example snippets
// The template directory in your theme to save the html views parts
'blocks.template.directory' => 'templates/blocks/',
// The blocks classes directory
'blocks.src.directory' => 'src/Services/PageBuilder/Blocks/',
// The template acf directory in your theme to save the additional admin styles and scripts
'blocks.acf.directory' => 'templates/acf/',
// Your blocks root namespace based on your app
'blocks.rootNamespace' => ($c['rootNamespace'] ?? 'App') . '\\Services\\PageBuilder\\Blocks',
// The blocks library containing all of your blocks
'blocks' => $c->get('pageBuilder.library')
// The fields directory to create and write complex fields groups
'fields.directory' => 'src/admin/fields/blocks/',
// The block thumbnail directory to save the blocks previews thumbnails
'fields.thumbnails.directory' => \get_stylesheet_directory() . '/assets/images/admin/acf/',
// The block thumbnail url to get the blocks previews thumbnails
'fields.thumbnails.baseUrl' => '<##ASSETS_URL##>/images/admin/acf/',
// Example to change the template directory
add_filter('coretik/page-builder/config', function ($config) {
$config['blocks.template.directory'] = 'my-theme-templates/';
return $config;
});
namespace Coretik\PageBuilder\Library\Component;
use Coretik\PageBuilder\Core\Block\BlockComponent;
use StoutLogic\AcfBuilder\FieldsBuilder;
class TitleComponent extends BlockComponent
{
const NAME = 'component.title';
const LABEL = 'My title'; // Admin label
/**
* All fields to be retrieved must be declared as property class.
* There are automatically populated with values from the database.
*/
protected $title;
protected $tag;
public function fieldsBuilder(): FieldsBuilder
{
$field = $this->createFieldsBuilder();
$field
// First field : 'title'
->addText('title')
->setLabel('Title')
->setRequired()
// Second field : 'tag'
->addRadio('tag', ['layout' => 'horizontal'])
->setLabel('Title level')
->addChoice('h2')
->addChoice('h3')
->addChoice('h4')
->addChoice('h5')
->setDefaultValue('h2')
->setRequired();
$this->useSettingsOn($field);
return $field;
}
/**
* The block formatted data. You can apply your own format rules.
*/
public function toArray()
{
return [
'title' => $this->title,
'tag' => $this->tag
];
}
/**
* This is usefull to get html from light component without template file
*/
protected function getPlainHtml(array $parameters): string
{
// Return <hN>A title from my acf field</hN>
return sprintf(
'<%1$s class="my_title_class">%2$s</%1$s>',
$parameters['tag'],
$parameters['title']
);
}
}
use Components;
$titleComponent = $this->component('component.title'); // Or with some defined values : $this->component(['acf_fc_layout' => 'component.title', 'tag' => 'h2'])
$titleFields = $titleComponent->fields();
[...]
namespace Coretik\PageBuilder\Library\Block;
use Coretik\PageBuilder\Core\Block\BlockComposite;
use Coretik\PageBuilder\Library\{
Component\TitleComponent,
Component\WysiwygComponent,
};
use function Coretik\PageBuilder\Core\Block\Modifier\ENDER_COMPONENTS = RenderingType::Html;
/**
* Define all sub blocks to build in this composite block.
* The acf fields will be constructed and rendered from each component.
*/
protected function prepareComponents(): array
{
return [
'title' => TitleComponent::class,
/**
* Some modifiers functions are available to help you to build specifics composite blocks.
* See `/src/Core/Block/Modifier/modifiers.php`
*/
'editor' =>
// Get the flexible content instance
$pageBuilder = app()->get('pageBuilder.field');
// You can filter ou use some specifics blocks as necessary
$pageBuilder->setBlocks(app()->get('pageBuilder.library')->filter());
// Generate the FieldsBuilder with your $fieldName, example "blocks"
$pageBuilder = $pageBuilder->field('blocks');
$page = new FieldsBuilder('page_builder', [
'title' => 'Builder',
'acfe_autosync' => ['php'],
'hide_on_screen' => [
'the_content',
'custom_fields',
],
'position' => 'normal',
'style' => 'seamless',
'label_placement' => 'top',
'instruction_placement' => 'label'
]);
$page
->addFields($pageBuilder)
->setLocation('post_type', '==', 'page');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.