PHP code example of coderstm / laravel-page-builder
1. Go to this page and download the library: Download coderstm/laravel-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/ */
coderstm / laravel-page-builder example snippets
return [
// Base URL path for the page builder routes (e.g., 'pagebuilder' or 'foo')
'prefix' => 'pagebuilder',
// The prefix for the page builder public pages and editor.
// If your pages are served at /foo/*, set this to 'foo'.
'basePath' => '/',
// Additional query parameters to preserve during editor navigation
'preserved_params' => [],
// Path to page JSON data files
'pages' => resource_path('views/pages'),
// Path to section Blade templates
'sections' => resource_path('views/sections'),
// Path to theme block Blade templates
'blocks' => resource_path('views/blocks'),
// Path to JSON template files (fallback layouts for pages without a page JSON)
'templates' => resource_path('views/templates'),
// Middleware applied to editor routes
'middleware' => ['web'],
// Filesystem disk for asset uploads
'disk' => 'public',
// Directory within the disk for uploaded assets
'asset_directory' => 'pagebuilder',
// Reserved slugs that cannot be used for dynamic pages
'preserved_pages' => ['home', 'admin', 'user', 'api', 'storage', 'uploads', 'files', 'vendor'],
// Path to the JSON file storing theme setting values
'theme_settings_path' => resource_path('settings.json'),
];
use Coderstm\PageBuilder\Facades\Page;
class PageController extends Controller
{
public function show(string $slug)
{
return Page::render($slug);
}
}
use Coderstm\PageBuilder\Facades\Page;
// Render from slug (loads JSON from disk)
$html = Page::render('home');
// Render with extra meta passed to the page model/template
$html = Page::render('home', ['title' => 'My Home Page']);
use Coderstm\PageBuilder\Facades\Section;
use Coderstm\PageBuilder\Facades\Block;
// In a service provider's boot() method
Section::add(resource_path('views/custom-sections'));
Block::add(resource_path('views/custom-blocks'));
use Coderstm\PageBuilder\Facades\Section;
use Coderstm\PageBuilder\Schema\SectionSchema;
Section::register('custom-hero', new SectionSchema([
'name' => 'Custom Hero',
'settings' => [
['id' => 'title', 'type' => 'text', 'label' => 'Title', 'default' => 'Hello'],
],
]), 'my-views::sections.custom-hero');
use Coderstm\PageBuilder\PageBuilder;
public function boot()
{
PageBuilder::auth(function ($request) {
// Return true if the user is authorized to access the editor
return auth()->check() && auth()->user()->is_admin;
});
}
// Check if editor mode is active
pb_editor(); // Returns bool
// In Blade templates
@if(pb_editor())
{{-- Editor-only content --}}
@endif
use Coderstm\PageBuilder\Facades\Theme;
use Coderstm\PageBuilder\Facades\Section;
use Coderstm\PageBuilder\Facades\Block;
// Set the active theme (for example in a ThemeServiceProvider or middleware)
Theme::set('my-theme');
// The package will automatically register the following directories if they exist:
// themes/my-theme/views/sections
// themes/my-theme/views/blocks
// If you need to register additional paths manually you can still call:
Section::add(base_path('themes/my-theme/views/sections'));
Block::add(base_path('themes/my-theme/views/blocks'));