Installation
composer require bnine/mdeditorbundle
php bin/console assets:install
Verify assets are copied to public/bundles/bninemdeditor/.
Include JS in Base Layout
Add this to your base.html.twig (or equivalent):
<script src="{{ asset('bundles/bninemdeditor/bninemdeditor.js') }}"></script>
First Use Case: Basic Form Integration
use Bnine\MdEditorBundle\Form\Type\MarkdownType;
$builder->add('content', MarkdownType::class, [
'label' => 'Markdown Content',
'required' => false,
]);
Render the form in Twig:
{{ form_row(form.content) }}
Form Integration
MarkdownType for any text area needing Markdown editing.$builder->add('description', MarkdownType::class, [
'config' => ['spellChecker' => false], // Pass EasyMDE config
'attr' => ['class' => 'custom-editor'], // Add custom classes
]);
Asset Management
easymde.min.css and easymde.min.js (v2.10.0).public/bundles/bninemdeditor/ and updating config/packages/bninemdeditor.yaml:
bninemdeditor:
assets:
js: 'custom-path/easymde.min.js'
css: 'custom-path/easymde.min.css'
Dynamic Initialization
// Initialize all editors on page
document.addEventListener('DOMContentLoaded', function() {
BnineMdEditor.init();
});
BnineMdEditor.init('#custom-editor-id');
Symfony UX Integration
$builder->add('notes', MarkdownType::class, [
'attr' => ['data-turbo-frame' => '_self'],
]);
Asset Loading Order
bninemdeditor.js is loaded after jQuery (EasyMDE dependency).console.log(jQuery.fn.easymde); // Should return EasyMDE constructor
Configuration Merging
config options in MarkdownType override defaults, not merge.toolbar: false will disable all toolbars.Twig Autoescape
|raw in Twig if rendering raw:
{{ form.content.vars.data|raw }}
Symfony 7+ Compatibility
assets:install behavior).BnineMdEditor is available.{{ dump(form.content.vars.data) }} to debug submitted Markdown.const editor = document.querySelector('.editor').easymde;
console.log(editor);
Custom EasyMDE Plugins
bninemdeditor.js to include plugins:
// In your custom JS file
BnineMdEditor.extendConfig = function(config) {
config.plugins = ['spellChecker', 'table'];
return config;
};
Override Form Theme
MarkdownType theme in config/packages/twig.yaml:
twig:
form_themes: ['@BnineMdEditor/form/markdown.html.twig']
vendor/bnine/mdeditorbundle/resources/views/form/markdown.html.twig.Server-Side Processing
Markdown DTO (from Bnine\MdEditorBundle\Dto) for type safety:
use Bnine\MdEditorBundle\Dto\Markdown;
$builder->add('content', MarkdownType::class, [
'data_class' => Markdown::class,
]);
How can I help you explore Laravel packages today?