Installation:
composer require bbit/blog-bundle:dev-master
Ensure knp-markdown-bundle and eko/feedbundle are also installed (required dependencies).
Enable Bundle:
Add new BBIT\BlogBundle\BBITBlogBundle() to AppKernel::registerBundles().
Basic Configuration:
Update config.yml with minimal settings:
bbit_blog:
extend_template: 'YourBundle:Default:layout.html.twig' # Must include a `blogContent` block
disqus_shortname: 'YourDisqusShortname' # Required for comments
First Use Case: Run migrations to create the blog tables:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
Access /blog to see the default blog listing.
Post Management:
BBITBlogBundle:Post:new to create posts via a form.{% extends 'YourBundle:Default:layout.html.twig' %}
{% block blogContent %}
{% for post in posts %}
<h2>{{ post.title }}</h2>
{{ post.content|markdown }}
{% endfor %}
{% endblock %}
Routing:
/blog → Lists all posts./blog/{slug} → Shows a single post.routing.yml:
bbit_blog_post:
resource: "@BBITBlogBundle/Resources/config/routing.yml"
prefix: /my-custom-prefix
Feeds:
bbit_blog.eko_feed:
eko_feed:
feeds:
post:
title: 'Your Blog Feed'
link:
route: bbit_blog_post_index # Override default route
Integration with Forms:
BBIT\BlogBundle\Form\PostType form to add custom fields:
use BBIT\BlogBundle\Form\PostType as BasePostType;
class ExtendedPostType extends BasePostType {
public function buildForm(FormBuilderInterface $builder, array $options) {
parent::buildForm($builder, $options);
$builder->add('custom_field', TextType::class);
}
}
services.yml to replace the default form:
services:
bbit_blog.form.post_type:
class: YourBundle\Form\ExtendedPostType
tags:
- { name: form.type, alias: bbit_blog_post }
Template Block Requirement:
extend_template must include a blogContent block. Forgetting this causes a Twig_Error_Runtime.{# ... #}
{% block blogContent %}{% endblock %}
Markdown Dependencies:
knp-markdown-bundle is properly configured with a parser (e.g., commonmark).knp_markdown.parser.class in config.Feed Generation:
eko_feed configuration is incomplete./feed/atom or /feed/rss after setup.Slug Conflicts:
services:
bbit_blog.slugger:
class: YourBundle\Service\CustomSlugger
arguments: ['@doctrine.orm.entity_manager']
Enable Debug Mode:
# config.yml
framework:
profiler: { only_exceptions: false }
Check the profiler for SQL queries and Twig errors.
Log Migrations: Run migrations with verbose output:
php bin/console doctrine:migrations:migrate --dry-run -v
Clear Cache: After configuration changes, clear the cache:
php bin/console cache:clear
Custom Post Types:
Post entity to add fields:
// src/YourBundle/Entity/Post.php
use BBIT\BlogBundle\Entity\Post as BasePost;
class Post extends BasePost {
/**
* @ORM\Column(type="string", nullable=true)
*/
private $customField;
}
Override Controllers:
PostController:
services:
bbit_blog.controller.post:
class: YourBundle\Controller\PostController
arguments: ['@service_container']
tags:
- { name: controller.service_arguments }
Add Custom Routes:
# src/YourBundle/Resources/config/routing.yml
your_blog_custom_route:
path: /blog/tag/{tag}
defaults: { _controller: YourBundle:Post:taggedPosts }
How can I help you explore Laravel packages today?