2

I need to install this plugin on my application, so I followed the instruction and executed:

npm install --save @ckeditor/ckeditor5-upload

Usually, to load a plugin I create a file inside the load directory which contains the plugin name, in particular:

Views
    load
        ckeditor.php

which contains this:

<!-- Push section js -->
<?= $this->section('js') ?>
<script src="https://cdn.ckeditor.com/ckeditor5/27.1.0/classic/ckeditor.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/27.1.0/classic/translations/it.js"></script>
<?= $this->endSection() ?>

so to include in a specific section of my app, I simply do:

<?= $this->include('App\Views\Backend\load\ckeditor') ?>

and this will inject the plugin into my app, but how can I do this with local dependencies installed via npm?

sfarzoso
  • 1,356
  • 2
  • 24
  • 65

3 Answers3

1

It looks like you want to use NPM modules client-side, which you actually can do. Check out Browserify: https://browserify.org/

It allows you to bundle up all the dependencies of NPM modules into JS code that you can deliver to the client, allowing you to use those NPM modules as 'native' functions in your client-side Javascript.

parttimeturtle
  • 1,125
  • 7
  • 22
0

NPM (node package manager) packages are used for applications that run on node.js. Since your app is using PHP on backend, it's not suited to import backend JS packages.

In general, you can't use a backend JS package on a frontend because it usually contains code that is not available in the browser JS (such as accessing local files).

You'll need to find some other package that does a similar thing but for combination of PHP and browser JS.


Note: Configuring your HTTP server (usually Apache or Nginx) to publish the node_modules and link the (public URL of) NPM package from the frontend is a bad practice. Plus this particular package won't work anyway because it's using features that are not available in the browser JS.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
0

In order to use CKEditor in your PHP application, The simplest way is to use CKEditor online builder tool and download complied version of the CKEditor code, and place it in your PHP application. Visit: CKEditor online build

Follow the below steps:

  1. Visit the above link of the CKEditor Online Build Tool.
  2. Select Choose editor type as your desired editor.
  3. Select the desired plugin that you want in your editor.
  4. In the next section drag/drop and customize your editor layout.
  5. At last select language and download the zip file.
  6. Extract it and place it in your application's public folder eg. public/ckeditor5.
  7. Now navigate to the downloaded folder and open the index.html under sample folder (public/ckeditor5/sample/index.html)
  8. Copy last both scripts and place them in your working file where you want to use CKEditor. Don't forget to modify the relative path of your ../build/ckeditor.js file.
iabhitech
  • 66
  • 5