Install the Bundle
composer require ajgl/h5bp-bundle
Register the bundle in config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 2/3):
Ajgl\H5bpBundle\AjglH5bpBundle::class => ['all' => true],
Enable Twig Templates
Import the bundle’s routing and assets in config/packages/twig.yaml (Symfony 4+):
twig:
paths:
'%kernel.project_dir%/vendor/ajgl/h5bp-bundle/Resources/views': h5bp
First Use Case: Render a Base Template Extend the H5BP layout in your controller or Twig template:
{% extends 'h5bp/base.html.twig' %}
{% block title %}My Page Title{% endblock %}
{% block content %}
<h1>Hello, H5BP!</h1>
{% endblock %}
Template Inheritance
base.html.twig as the parent template for all pages.title, head, content, and footer:
{% block head %}
{{ parent() }} {# Inherits default H5BP meta tags #}
<meta name="theme-color" content="#317EFB">
{% endblock %}
Asset Integration
{% block stylesheets %}
{{ parent() }} {# Loads h5bp.css #}
{{ encore_entry_link_tags('app') }} {# For Webpack Encore #}
{% endblock %}
Responsive Design
.skip-link, .visually-hidden) directly in Twig:
<a href="#main" class="skip-link">{{ 'Skip to content'|trans }}</a>
Symfony Integration
app.request) to Twig:
{% block head %}
{{ parent() }}
<title>{{ app.request.get('page_title', 'Default') }}</title>
{% endblock %}
Resources/views/base.html.twig to your project (e.g., templates/base_custom.html.twig) and extend it.favicon.ico in public/ or use Twig:
{% block favicon %}
<link rel="icon" href="{{ asset('images/favicon-' ~ app.request.get('theme')) }}.ico">
{% endblock %}
Symfony Version Mismatch
composer.json). For Symfony 4/5, manually adapt Twig paths or fork the bundle.symfony/framework-bundle:^4.0 with a wrapper or replace Twig paths in config/packages/twig.yaml.Asset Path Conflicts
stylesheets/javascripts blocks entirely:
{% block stylesheets %}{% endblock %}
{% block javascripts %}{% endblock %}
Missing Documentation
Resources/doc/index.md is referenced but not publicly hosted.Resources/views/base.html.twig for block names and structure.{{ _context.getParent() }} in Twig to debug inheritance.php bin/console cache:clear
Customize H5BP Variables
return $this->render('my_template.html.twig', [
'h5bp_custom_vars' => ['analytics_id' => 'UA-12345'],
]);
{% if h5bp_custom_vars.analytics_id %}
<script>window.gaId = "{{ h5bp_custom_vars.analytics_id }}";</script>
{% endif %}
Override Partial Templates
Resources/views/partials/ to templates/partials/ to customize components (e.g., header.html.twig).Add Modern Features
base.html.twig:
{% block head %}
{{ parent() }}
<style>:root { --primary-color: #317EFB; }</style>
{% endblock %}
How can I help you explore Laravel packages today?