composer require friendsofsymfony/ckeditor-bundle
config/bundles.php:
return [
// ...
FriendsOfSymfony\CKEditorBundle\FOSCKEditorBundle::class => ['all' => true],
];
config/packages/fos_ck_editor.yaml:
fos_ck_editor:
base_path: /bundles/fosckeditor
config: config/ckeditor.yml
use FriendsOfSymfony\CKEditorBundle\Form\Type\CKEditorType;
$builder->add('content', CKEditorType::class, [
'config' => ['toolbar' => 'Full'],
]);
php bin/console cache:clear
Replace a plain textarea with a rich-text editor in a blog post form:
{{ form_row(form.content) }}
The editor will render automatically, with the content saved as HTML in your database.
CKEditorType in Symfony forms for fields requiring rich text.'toolbar' => ['Basic', 'Full']) to control editor features.$builder->add('description', CKEditorType::class, [
'config' => [
'toolbar' => ['Bold', 'Italic', 'NumberedList', 'BulletedList'],
'removePlugins' => 'elementspath',
],
]);
config option.$builder->add('bio', CKEditorType::class, [
'config' => ['removePlugins' => 'image'],
]);
public/bundles/fosckeditor/ (default base_path).fos_ck_editor.yaml:
fos_ck_editor:
base_path: /custom/path
{{ form_widget(form.content, {'attr': {'class': 'ckeditor'}}) }}
fos_ck_editor_include_javascript to load CKEditor in non-form contexts:
{{ fos_ck_editor_include_javascript('my_editor') }}
<textarea id="my_editor"></textarea>
config/ckeditor.yml:
toolbar:
Basic: [Bold, Italic, Underline]
Full: [Bold, Italic, Underline, 'NumberedList', 'BulletedList', 'Blockquote']
$builder->add('content', CKEditorType::class, ['config' => ['toolbar' => 'Full']]);
config/ckeditor.yml:
filebrowserUploadUrl: /upload
filebrowserUploadHandler: custom_handler
SymfonyUploaderBundle or custom logic).composer.json for stability:
"friendsofsymfony/ckeditor-bundle": "^2.0"
CKEditorType as a drop-in replacement for TextareaType where rich text is needed.Symfony\Component\Validator\Constraints\Html).base_path in fos_ck_editor.yaml points to a writable directory.Symfony\Component\DomCrawler\Crawler or HTMLPurifier)..jpg, .png) and validate sizes.document.addEventListener('DOMContentLoaded', function() {
ClassicEditor.create(document.querySelector('#my_editor'));
});
base_path in fos_ck_editor.yaml or missing assets.public/bundles/fosckeditor/ exists and is writable.php bin/console assets:install if using Symfony’s asset system.php bin/console cache:clear
config/ckeditor.yml settings are ignored.config/ckeditor.yml is in the correct location (e.g., config/packages/fos_ck_editor.yml for Symfony 4.4+).yaml.lint or an online validator)._csrf_token in upload requests.// In your upload controller
$this->denyAccessUnlessGranted('IS_AUTHENTICATED', null, 'Cannot upload without authentication');
csrf_token helper in Twig for hidden fields.Html constraint:
use Symfony\Component\Validator\Constraints as Assert;
$builder->add('content', CKEditorType::class, [
'constraints' => [new Assert\Html()],
]);
HTMLPurifier:
$purifier = new \HTMLPurifier();
$cleanHtml = $purifier->purify($dirtyHtml);
$ or jQuery conflicts.jQuery.noConflict() if jQuery is loaded.document.addEventListener('DOMContentLoaded', function() {
ClassicEditor.create(document.querySelector('#my_editor'));
});
public/uploads/) is writable:
chmod -R 775 public/uploads/
failed to open stream).config/ckeditor.yml.Bold, not bold).F12) and inspect the Console and Network tabs for:
CKEDITOR is not defined).APP_DEBUG=true in .env to see detailed errors.{% if app.debug %}
<pre>{{ dump(f
How can I help you explore Laravel packages today?