Symfony
Welcome to the Symfony-specific documentation for On-Codemerge, an advanced web editor that can be seamlessly integrated into Symfony applications, blending Symfony's robust backend features with powerful frontend editing capabilities.
Getting Started with Symfony
To integrate On-Codemerge into your Symfony project, you'll first need to set up the frontend environment within Symfony's structure.
Installation
-
Setup Symfony Encore: Symfony Encore is a simpler way to integrate Webpack into your Symfony application. If you haven't already set up Encore, you can do so by following the official Symfony documentation.
-
Install
on-codemerge
: Once Encore is set up, install theon-codemerge
package using npm or yarn in your Symfony project.
npm install --save on-codemerge
or
yarn add on-codemerge
Symfony Integration Example
Here's a step-by-step guide to integrating On-Codemerge into a Symfony project:
- Configure Encore: In your
webpack.config.js
, set up Encore to compile your JavaScript assets.
const Encore = require('@symfony/webpack-encore');
Encore
// ... other configurations
.addEntry('app', './assets/js/app.js')
// ... other configurations
module.exports = Encore.getWebpackConfig();
- Initialize On-Codemerge: In your
assets/js/app.js
, import and initialize On-Codemerge.
import EditorCore from 'on-codemerge';
import TextStylingButton from 'on-codemerge/textStylingButton';
import TableButton from 'on-codemerge/tableButton';
document.addEventListener('DOMContentLoaded', () => {
const editorElement = document.getElementById('editor');
if (editorElement) {
const editor = new EditorCore(editorElement);
editor.registerModule(new TextStylingButton());
editor.registerModule(new TableButton());
// ... additional configuration
editor.subscribeToContentChange((newContent) => {
console.log('Content changed:', newContent);
});
editor.setContent("Initial content goes here");
}
});
- Build Your Assets: Use Encore to build your assets.
npm run encore dev
or
yarn encore dev
- Include the Script in Your Twig Template: In your Twig template, include the compiled JavaScript file.
<!DOCTYPE html>
<html>
<head>
<!-- Head Contents -->
</head>
<body>
<div id="editor"></div>
{{ encore_entry_script_tags('app') }}
</body>
</html>
The encore_entry_script_tags
function will correctly insert the <script>
tags for your app
entry.
- Routing and Controller Setup: Ensure you have a route and controller set up in Symfony to render the Twig template that includes On-Codemerge.
By following these steps, you can integrate On-Codemerge into a Symfony application, taking advantage of Symfony's structured approach to managing frontend assets. This integration allows you to use On-Codemerge's rich text editing capabilities within the context of Symfony's powerful backend framework.