composer require alexdw/trumbowyg-bundle
config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 2/3):
Alexdw\TrumbowygBundle\AlexdwTrumbowygBundle::class => ['all' => true],
php bin/console assets:install public
base.html.twig):
{{ trumbowyg_js() }}
{{ trumbowyg_css() }}
Add a Trumbowyg field to a form type:
use Alexdw\TrumbowygBundle\Form\Type\TrumbowygType;
$builder->add('content', TrumbowygType::class, [
'label' => 'Article Content',
'attr' => ['class' => 'editor-full-width'],
]);
config/packages/alexdw_trumbowyg.yaml):
alexdw_trumbowyg:
btns:
- ["bold", "italic"]
- ["insertImage"]
$builder->add('content', TrumbowygType::class, [
'btns' => [["bold"], ["link"]],
'autogrow' => true,
]);
vendor/alexdw/trumbowyg-bundle/Resources/public/) to public/bundles/alexdwtrumbowyg/ and customize.{{ trumbowyg_js({'include_jquery': false}) }} if jQuery is already loaded.{% if app.request.attributes.get('_route') == 'admin_article_edit' %}
{{ trumbowyg_js() }}
{% endif %}
$content = $form->get('content')->getData(); // Returns HTML string
HtmlPurger or DOMPurify to sanitize output before saving to DB.{{ trumbowyg_js({
'btns': [['customButton']],
'plugins': {'customPlugin': '/path/to/plugin.js'}
}) }}
{{ trumbowyg_js({'language': app.request.locale }) }}
Asset Paths:
base_path in config matches your assets:install output.public/ is the web root (not public/index.php).jQuery Dependency:
include_jquery: true conflicts with existing jQuery, set it to false and ensure jQuery is loaded first.Form Theming:
templates/form/trumbowyg_widget.html.twig) to customize the wrapper or add classes.CSRF Tokens:
{{ csrf_token() }} is included in forms.Database Storage:
Custom Buttons: Add a button via JavaScript:
{{ trumbowyg_js({
'btns': [['customButton']]
}) }}
Then define the button in a separate JS file:
$.extend(true, $.trumbowyg.svgPath, '/bundles/alexdwtrumbowyg/ui/');
$.trumbowyg.btns.push({
xtag: 'customButton',
fn: function() { /* Logic */ }
});
Event Listeners:
Hook into Trumbowyg events (e.g., tbwChange) via JavaScript:
{{ trumbowyg_js() }}
<script>
$('#my-editor').on('tbwChange', function() {
console.log('Content changed!');
});
</script>
Configuration Overrides:
Override bundle config in config/packages/alexdw_trumbowyg.yaml:
alexdw_trumbowyg:
btns:
- ["bold", "italic", "strikethrough"]
autogrow: true
Symfony 5+ Flex Compatibility:
If using Symfony Flex, manually register the bundle in config/bundles.php (Flex may not auto-discover it).
language config for multilingual support (e.g., language: '{{ app.request.locale }}').How can I help you explore Laravel packages today?