Skip to content

globaldesignindia/laravel-grapesjs

 
 

Repository files navigation

Installation

composer require jd-dotlogics/laravel-grapesjs

Publish files & migrate

php artisan vendor:publish --provider="Dotlogics\Grapesjs\GrapesjsServiceProvider"

php artisan migrate

Get Start

  1. Add 'gjs_data' column to the model's database table (e.g Page), for which you are going to use the editor.

  2. Implement Editable Interface and use the EditableTrait trait for the Model class

use Illuminate\Database\Eloquent\Model;
use Dotlogics\Grapesjs\App\Traits\EditableTrait;
use Dotlogics\Grapesjs\App\Contracts\Editable;

class Page extends Model implements Editable
{
    use EditableTrait;

    ...
}
  1. Next Create a Route for editor
Route::get('pages/{page}/editor', 'PageController@editor');
  1. In your controller, use the EditorTrait and add the editor method
<?php

namespace App\Http\Controllers;

use App\Models\Page;
use Illuminate\Http\Request;
use Dotlogics\Grapesjs\App\Traits\EditorTrait;

class PageController extends Controller
{
    use EditorTrait;

    ...


    public function editor(Request $request, Page $page)
    {
        return $this->show_gjs_editor($request, $page);
    }

    ...
}
  1. Open this route /pages/:page_id/editor (where the :page_id is the id of your model)

Placeholders

Placeholders are like short-code in wordpress. The synax of placeholder is

[[This-Is-Placeholder]]

Create a file named "this-is-placeholder.blade.php" in "/resources/views/vendor/laravel-grapesjs/placeholders" directory.

The the placeholder will be replaced by the content of the relative blade file "this-is-placeholder.blade.php"

Templates

You can create a template (a block) in the "/resources/views/vendor/laravel-grapesjs/templates" directory. And the templates will be availabe in the block section of edittor.

Display output

The "Editable" model (e.g. Page) will have two public properties, css and html. In your blade file you can use these properties to display the content.

<style type="text/css">
	{!! $page->css !!}
</style>

{!! $page->html !!}

Thank you for using.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 51.5%
  • JavaScript 43.0%
  • Blade 5.4%
  • SCSS 0.1%