PHP code example of symbioticwp / acf-page-builder

1. Go to this page and download the library: Download symbioticwp/acf-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/ */

    

symbioticwp / acf-page-builder example snippets



if (file_exists($composer = __DIR__ . '/vendor/autoload.php')) {
    



add_action('symbiotic/acf_page_builder/register_page_blocks', function($pageBuilder) {

    // Create Blocks directly with an array
	$pageBuilder->addLayout([
		'label'      => 'Text Block',
		'name'       => 've-text-block',
		'display'    => 'block',
		'sub_fields' => [
			acf_tab(['label' => 'Details']),
			acf_text( [ 'label' => 'Title', 'name' => 've-text-title' ] ),
			acf_wysiwyg( [ 'label' => 'Content', 'name' => 've-text-content' ] ),
		]
	]);

	$pageBuilder->addLayout([
		'label'      => 'Image Block',
		'name'       => 've-image-block',
		'display'    => 'block',
		'sub_fields' => [
			acf_tab(['label' => 'Details']),
			acf_image( [ 'label' => 'Image', 'name' => 've-image-block' ] ),
			acf_text( [ 'label' => 'Aspect Ratio', 'name' => 've-aspect-ratio', 'default_value' => '16:9' ] ),
		]
	]);
});



namespace App\Blocks;

use Symbiotic\AcfPageBuilder\Blocks\AbstractBlock;

class TemplateBlock extends AbstractBlock {

	protected function registerLayout() {
		return [
			'label'      => 'Template Block',
			'name'       => 've-template-block',
			'display'    => 'block',
			'sub_fields' => [
				acf_tab(['label' => 'Details']),
				acf_text( [ 'label' => 'Path to Template File', 'name' => 've-template-filename' ] ),
			]
		];
	}

	public function render() {
		$this->



use App\Blocks\TemplateBlock;

add_action('symbiotic/acf_page_builder/register_page_blocks', function($pageBuilder) {

    // Initialize Blocks with a class (for complex logic)
	$pageBuilder->addLayout(new TemplateBlock());
});


/**
 * Add a settings Tab to every Block
 */
 
add_action('symbiotic/acf_page_builder/add_layout_after', function($layoutConfig) {
	if(!isset($layoutConfig['sub_fields'])) {
		var_dump($layoutConfig);
	}
	$layoutConfig['sub_fields'] = array_merge(
		$layoutConfig['sub_fields'],
		addSettingsTab()
	);

	return $layoutConfig;
});

/**
 *
 * @return array
 */
function addSettingsTab() {
	return [
		acf_tab(['label' => 'Settings']),
		acf_text([ 'label' => 'Container Class',
		            'name' => 've-settings-container',
					'instructions' => 'You can define your own container classes which gets 


add_action('symbiotic/acf_page_builder/set_location', function($location) {
	$location[] = [acf_location('post_type', 'portfolio')];
	$location[] = [acf_location('post_type', 'services')];
	return $location;
});