Installation:
composer require arkounay/block-bundle
Add to AppKernel.php:
new Arkounay\BlockBundle\ArkounayBlockBundle(),
Assets & Routes:
php bin/console assets:install
Import routes in routing.yml:
block:
resource: "@ArkounayBlockBundle/Resources/config/routing.yml"
Twig Setup: Include CSS/JS in your base template:
{% include '@ArkounayBlock/assets/include_css.html.twig' %}
{% if has_inline_edit_permissions() %}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/4.4.3/tinymce.min.js"></script>
{% endif %}
{% include '@ArkounayBlock/assets/include_js.html.twig' %}
First Editable Block:
{{ render_block('homepage_hero') }}
First edit creates a PageBlock entity in the DB.
Add a WYSIWYG-editable hero section to your homepage:
<div class="hero">
{{ render_block('homepage_hero', true, 'div') }}
</div>
Dynamic Blocks:
{% for section in ['header', 'footer', 'sidebar'] %}
{{ render_block(section) }}
{% endfor %}
Entity Field Integration:
{{ render_entity_field(post, 'content') }}
Post) with inline editing.Conditional Loading:
{% if app.user.hasRole('ROLE_EDITOR') %}
{% include '@ArkounayBlock/assets/include_js.html.twig' %}
{% endif %}
Custom TinyMCE Config:
Override the default JS template (@ArkounayBlock/assets/include_js.html.twig):
<script>
tinymce.init({
selector: '.js-arkounay-block-bundle-editable',
plugins: 'code table',
toolbar: 'bold italic | alignleft aligncenter alignright'
});
</script>
Database Schema: Run after installation:
php bin/console doctrine:schema:update --force
page_block table for block storage.Permissions:
Configure allowed roles in config.yml:
arkounay_block:
roles: ['ROLE_ADMIN', 'ROLE_EDITOR']
Shortcut Tags: Use predefined wrappers:
{{ render_span_block('small_text') }} {# Renders in <span> #}
TinyMCE Dependency:
CSRF Token Mismatch:
{% csrf_token %} is included in forms or templates.Database Conflicts:
page_block table exists.doctrine:schema:update.Role-Based Rendering:
has_inline_edit_permissions() may return false unexpectedly.{{ dump(app.user.getRoles()) }}
Check Block Existence:
php bin/console doctrine:query:sql "SELECT * FROM page_block WHERE id = 'block_id'"
TinyMCE Console Errors:
F12) to verify TinyMCE initialization:
console.log(tinymce.editors); // Check if editor is loaded
Ajax Debugging:
403 = permission issue).Custom Block Types:
Extend PageBlock entity to add metadata (e.g., layout_type):
// src/Entity/CustomBlock.php
class CustomBlock extends PageBlock {
private $layoutType;
}
Override Twig Functions: Create a custom Twig extension to modify rendering logic:
// src/Twig/BlockExtension.php
class BlockExtension extends \Twig_Extension {
public function getFunctions() {
return [
new \Twig_SimpleFunction('render_custom_block', [$this, 'renderCustomBlock']),
];
}
}
Event Listeners: Hook into block save events (e.g., log changes):
// src/EventListener/BlockListener.php
class BlockListener {
public function onBlockSave(BlockEvents $events) {
$block = $events->getBlock();
// Custom logic (e.g., analytics)
}
}
<script>tinymce.init({ cache_suffix: '' });</script>
How can I help you explore Laravel packages today?