ContentBuilder.js · Guide

Using ContentBuilder.js in a Laravel Project

ContentBuilder.js is a JavaScript library for creating elegant, editorial-style web content with simple drag and drop. In this guide we add it to a Laravel app, using Blade templates and Vite. First we embed the editor, then we add saving, uploads and a page that shows the saved content to visitors.

ContentBuilder comes in two parts:

ContentBuilder

The editor, used on the page where content is created.

ContentBuilder Runtime

Renders the saved content on your site. It makes interactive blocks (sliders, counters, charts, accordions and more) work, both while editing and when viewing.

In this guide

  1. Set up the project
  2. Embed the editor and the runtime
  3. Add saving and uploads
  4. Show the content to visitors
  5. Try it

Step 1

Set up the project

Create a Laravel project and install ContentBuilder and the Runtime:

composer create-project laravel/laravel my-app
cd my-app
npm install
npm install @innovastudio/contentbuilder @innovastudio/contentbuilder-runtime

The editor needs its assets (snippets, icons, fonts, plugins). They are in the ContentBuilder.js ZIP package, which you can download from your user area. Copy these into your project's public/ folder:

public/
├── assets/      # snippets, fonts, plugins
├── runtime/     # runtime files, used by the Live Preview page
└── preview.html # Live Preview page

Step 2

Embed the editor and the runtime

Create resources/js/editor.js:

// Editor
import ContentBuilder from '@innovastudio/contentbuilder'
import '@innovastudio/contentbuilder/public/contentbuilder/contentbuilder.css'

// Runtime
import ContentBuilderRuntime from '@innovastudio/contentbuilder-runtime'
import '@innovastudio/contentbuilder-runtime/dist/contentbuilder-runtime.css'

// Create the editor on the .container element. It edits the content inside it.
const builder = new ContentBuilder({
    container: '.container',
})

// Load the blocks users can drag in
builder.loadSnippets('/assets/minimalist-blocks/content-plugins.js')

// Start the runtime, so interactive blocks work while editing
const runtime = new ContentBuilderRuntime({
    pluginFolder: window.location.origin + '/assets/plugins/',
})
runtime.init()

// Make the runtime available to the editor
window.builderRuntime = runtime

The runtime makes interactive blocks (sliders, counters, charts, accordions and more) work while you edit. pluginFolder tells it where the plugins are. A plugin's files are loaded only when the content uses it.

Create the page, resources/views/edit.blade.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Edit</title>
    @vite('resources/js/editor.js')
</head>
<body>
    <div class="container" style="max-width: 840px; margin: 140px auto; padding: 0 20px">
        <div class="row">
            <div class="column">
                <h1>Hello World</h1>
                <p>Start editing your content here.</p>
            </div>
        </div>
    </div>
</body>
</html>

Add the route in routes/web.php:

Route::view('/edit', 'edit');

Tell Vite about the new script. In vite.config.js, add resources/js/editor.js to input:

input: ['resources/css/app.css', 'resources/js/app.js', 'resources/js/editor.js'],

Run it:

composer run dev

Open http://localhost:8000/edit. You have a working editor: click the text to edit it, and drag blocks in from the panel on the right, including interactive ones like a countdown or a chart.

The ContentBuilder.js editor in a Laravel app after step 2, with Hello World

The editor after step 2. Click the text to edit it, and drag blocks in from the panel.

Step 3

Add saving and uploads

Now let's add saving and uploads. The content is saved to a file in Laravel's storage, so you can run it without a database.

At the top of routes/web.php, add:

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

Then replace the /edit route with these three routes:

// The editor, with the saved content
Route::get('/edit', function () {
    return view('edit', ['html' => Storage::get('content.html')]);
});

// Saves the content
Route::post('/save', function (Request $request) {
    Storage::put('content.html', (string) $request->input('html'));

    return ['ok' => true];
});

// Saves an uploaded file and returns its URL
Route::post('/upload', function (Request $request) {
    $request->validate([
        'file' => 'required|file|mimes:jpg,jpeg,png,gif,webp,svg,mp4,webm,mp3,wav,pdf',
    ]);
    $path = $request->file('file')->store('uploads', 'public');

    return ['url' => '/storage/' . $path]; // ContentBuilder needs { url }
});

Uploaded files are saved in storage/app/public/uploads. To make them reachable from the browser, run once:

php artisan storage:link

Replace resources/views/edit.blade.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>Edit</title>
    @vite('resources/js/editor.js')
</head>
<body>
    <div class="container" style="max-width: 840px; margin: 140px auto; padding: 0 20px">
        @if ($html)
            {!! $html !!}
        @else
            <div class="row">
                <div class="column">
                    <h1>Hello World</h1>
                    <p>Start editing your content here.</p>
                </div>
            </div>
        @endif
    </div>

    <div style="position: fixed; top: 20px; right: 20px; display: flex; gap: 8px">
        <button id="btnHtml">HTML</button>
        <button id="btnPreview">Preview</button>
        <button id="btnSave">Save</button>
    </div>
</body>
</html>

Replace resources/js/editor.js:

// Editor
import ContentBuilder from '@innovastudio/contentbuilder'
import '@innovastudio/contentbuilder/public/contentbuilder/contentbuilder.css'

// Runtime
import ContentBuilderRuntime from '@innovastudio/contentbuilder-runtime'
import '@innovastudio/contentbuilder-runtime/dist/contentbuilder-runtime.css'

// Laravel's CSRF token, sent with every request
const csrfToken = document.querySelector('meta[name="csrf-token"]').content

// Sends the file to the upload route, which returns { url }
async function upload(file) {
    const formData = new FormData()
    formData.append('file', file)
    const response = await fetch('/upload', {
        method: 'POST',
        headers: { 'X-CSRF-TOKEN': csrfToken },
        body: formData,
    })
    return response.json()
}

// Create the editor. It edits the content inside .container.
const builder = new ContentBuilder({
    container: '.container',
    previewURL: 'preview.html', // enables the Live Preview button
    upload,                     // handles image, video, audio and file uploads
})

// Load the blocks users can drag in
builder.loadSnippets('/assets/minimalist-blocks/content-plugins.js')

// Start the runtime, so interactive blocks work while editing
const runtime = new ContentBuilderRuntime({
    pluginFolder: window.location.origin + '/assets/plugins/',
})
runtime.init()

// Make the runtime available to the editor
window.builderRuntime = runtime

// Sends the edited content to the save route
async function save() {
    await fetch('/save', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrfToken },
        body: JSON.stringify({ html: builder.html() }),
    })
}

// Buttons
document.querySelector('#btnHtml').addEventListener('click', () => builder.viewHtml())
document.querySelector('#btnPreview').addEventListener('click', async () => {
    await save()
    window.open('/view', '_blank')
})
document.querySelector('#btnSave').addEventListener('click', async () => {
    await save()
    alert('Content saved!')
})

What's new

  • Saving: html() returns the edited content, which is sent to the save route. The next time, the /edit route puts the saved content in the page, and the editor edits it.
  • Uploads: upload is one function for all media. It sends the file to the upload route, which returns { url }.
  • CSRF: Laravel protects POST routes with a token. The page puts it in a meta tag, and the script sends it with each request.
  • Buttons: HTML opens the code view, Save saves, and Preview saves and opens the viewing page, which we add next.
  • Live Preview: previewURL adds a preview button to the editor, which uses public/preview.html.
The ContentBuilder.js editor in a Laravel app, with saved content loaded back in

Saved content loads back into the editor the next time you open it.

Step 4

Show the content to visitors

The viewing page is rendered on the server, so the content is already in the HTML that browsers and search engines receive. This is good for SEO. The page needs only the runtime, not the editor.

Add the route in routes/web.php:

Route::get('/view', function () {
    return view('view', ['html' => Storage::get('content.html')]);
});

Create resources/views/view.blade.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>View</title>
    @vite('resources/js/view.js')
</head>
<body>
    <div class="is-container" style="max-width: 840px; margin: 80px auto; padding: 0 20px">
        {!! $html ?: '<p>No content available.</p>' !!}
    </div>
</body>
</html>

Important: the viewing container must have the is-container class.

Create resources/js/view.js. It makes the interactive blocks in the content work:

import ContentBuilderRuntime from '@innovastudio/contentbuilder-runtime'
import '@innovastudio/contentbuilder-runtime/dist/contentbuilder-runtime.css'

const runtime = new ContentBuilderRuntime({
    pluginFolder: window.location.origin + '/assets/plugins/',
})
runtime.init()

And add it to input in vite.config.js:

input: ['resources/css/app.css', 'resources/js/app.js', 'resources/js/editor.js', 'resources/js/view.js'],

Step 5

Try it

With composer run dev running, open http://localhost:8000/edit, drag in some blocks and click Save. Click Preview to see the saved content on the viewing page.

The Laravel viewing page showing content saved with ContentBuilder.js

The viewing page, rendered on the server by Blade, shows the saved content to visitors.

Going to production

  • Build: run npm run build, then serve the app as usual.
  • Saving: replace the file in the /edit, /save and /view routes with your database or CMS.
  • Uploads: to use S3 or other storage, change the public disk in store() to your disk, and return the URL it gives.
  • Security: put the /edit, /save and /upload routes behind authentication (for example the auth middleware), so only your editors can edit, save and upload.

Resources

© 2026 InnovaStudio

This site is built with Site Builder Kit