Installation:
composer require apnet/layout-bundle:~3.1
Add bundles to AppKernel.php:
$bundles[] = new Apnet\AsseticImporterBundle\ApnetAsseticImporterBundle();
$bundles[] = new Apnet\LayoutBundle\ApnetLayoutBundle();
First Use Case: Extend the base layout in your Twig template:
{% extends "ApnetLayoutBundle::body.html.twig" %}
{% block title %}My Site{% endblock %}
body.html.twigimported_asset() Twig function (via ApnetAsseticImporterBundle).stylesheets_core, body_core, javascripts_core (see README for structure).Extending Layouts:
Override blocks in child templates (e.g., app/Resources/views/base.html.twig):
{% extends "ApnetLayoutBundle::body.html.twig" %}
{% block stylesheets_core %}
{{ parent() }} {# Include parent styles #}
<link href="{{ imported_asset('css/custom.css') }}" rel="stylesheet" />
{% endblock %}
Asset Management:
Use imported_asset() for versioned assets (e.g., imported_asset('bundles/app/js/main.js')).
Configure asset paths in config.yml:
apnet_assetic_importer:
bundles:
- AppBundle
Dynamic Content Injection:
Pass variables to the layout via Twig’s {% block %} or controller:
{% block meta_tags %}
<meta name="description" content="{{ page_description }}">
{% endblock %}
composer.json constraints).ApnetAsseticImporterBundle is configured for asset pipelines.stylesheets_core/javascripts_core.Bundle Dependency Conflicts:
apnet/layout-bundle requires Symfony 2.3/3.0 and Apnet’s Bootstrap/jQuery bundles.KnpLabs/KnpMenuBundle may conflict with preloaded JS).Asset Paths:
imported_asset() fails if assets aren’t in configured bundles (check apnet_assetic_importer.bundles).{{ dump(asset('path')) }} in Twig.Block Overrides:
{{ parent() }} removes inherited assets (e.g., Bootstrap CSS).{% block stylesheets_core %} {# Missing parent() #}
<link href="..." />
{% endblock %}
config.yml:
twig:
debug: true
strict_variables: true
php bin/console cache:clear --env=prod
Custom Layouts:
Override the entire layout by extending a different template (e.g., AcmeBundle::layout.html.twig).
Dynamic Blocks:
Use Twig’s {% block %} conditionally:
{% block extra_scripts %}
{% if app.user %}
<script src="{{ imported_asset('js/user.js') }}"></script>
{% endif %}
{% endblock %}
Configuration:
Extend apnet_layout config (if available) to modify default blocks or asset paths.
imported_asset() for cache-busting (e.g., imported_asset('css/main.css?v=1.2')).javascripts_core) if not needed.How can I help you explore Laravel packages today?