PHPackages                             roadiz/abstract-blog-theme - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. roadiz/abstract-blog-theme

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

roadiz/abstract-blog-theme
==========================

Abstract Blog middleware for your Roadiz theme.

2.1.1(2y ago)12.0kMITPHPPHP &gt;=7.4

Since Apr 10Pushed 2y ago5 watchersCompare

[ Source](https://github.com/roadiz/AbstractBlogTheme)[ Packagist](https://packagist.org/packages/roadiz/abstract-blog-theme)[ RSS](/packages/roadiz-abstract-blog-theme/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (7)Versions (56)Used By (0)

Abstract Blog Theme
===================

[](#abstract-blog-theme)

**Abstract Blog middleware for your Roadiz theme.**

- [Inheritance](#inheritance)
- [Dependency injection](#dependency-injection)
- [Add node-types](#add-node-types)
- [PostContainerControllerTrait](#postcontainercontrollertrait)
    - [Filtering](#filtering)
    - [Usage](#usage)
        - [Override PostContainerControllerTrait behaviour](#override-postcontainercontrollertrait-behaviour)
- [PostControllerTrait](#postcontrollertrait)
    - [Usage](#usage-1)
        - [Override PostControllerTrait behaviour](#override-postcontrollertrait-behaviour)
- [Search engine with Solr](#search-engine-with-solr)
    - [Override PostControllerTrait behaviour](#override-postcontrollertrait-behaviour-1)

    - [Search result model](#search-result-model)
- [AMP mobile page support](#amp-mobile-page-support)
- [Templates](#templates)
- [Twig extension](#twig-extension)
    - [Functions](#functions)
    - [Filters](#filters)

Inheritance
-----------

[](#inheritance)

Your own theme entry class must **extend** `AbstractBlogThemeApp` instead of `FrontendController` to provide essential methods:

```
use Themes\AbstractBlogTheme\AbstractBlogThemeApp;

class MyThemeApp extends AbstractBlogThemeApp
{
    //…
}
```

Dependency injection
--------------------

[](#dependency-injection)

Edit your own `app/AppKernel.php` to register Blog services:

```
use Themes\AbstractBlogTheme\Services\BlogServiceProvider;

/**
 * {@inheritdoc}
 */
public function register(\Pimple\Container $container)
{
    parent::register($container);
    $container->register(new BlogServiceProvider());
}
```

You must override these services in your custom theme:

- blog\_theme.post\_container\_entity
- blog\_theme.post\_entity

with your own node-type class names.

```
/**
 * @param Container $container
 */
public static function setupDependencyInjection(Container $container)
{
    parent::setupDependencyInjection($container);

    $container->extend('blog_theme.post_container_entity', function ($entityClass) {
        return NSBlogPostContainer::class;
    });

    $container->extend('blog_theme.post_entity', function ($entityClass) {
        return NSBlogPost::class;
    });
}
```

Add node-types
--------------

[](#add-node-types)

Abstract Blog theme declare 3 node-types to create your blog website:

- `BlogFeedBlock`: to create an automatic feed preview on any page
- `BlogPost`: the main blog post entity
- `BlogPostContainer`: the blog container to host every blog post

```
bin/roadiz themes:install --data Themes/AbstractBlogTheme/AbstractBlogThemeApp
bin/roadiz generate:nsentities
bin/roadiz orm:schema-tool:update --dump-sql --force
```

PostContainerControllerTrait
----------------------------

[](#postcontainercontrollertrait)

`PostContainerControllerTrait` will implement your `indexAction` by handling all request data to provide your posts, filters and available tags to build your template.

IndexAction will assign:

- `posts`: found `NodesSources` array according to your criteria
- `filters`: pagination information array
- `tags`: available filtering `Tag` array
- `currentTag`: `Tag`, `array` or `null`
- `currentTagNames`: `array` containing current filtering tag(s) name for your filter menu template.
- `currentRelationSource`: `NodesSources` or `null` containing the filtering related entity
- `currentRelationsSources`: `array` containing current filtering related entities(s) for your filter menu template.
- `currentRelationsNames`: `array` containing current filtering related entities(s) name for your filter menu template.
- `archives`: available *years* and *months* of post archives
- `currentArchive`: `string` or `not defined`
- `currentArchiveDateTime`: `\DateTime` or `not defined`

### Filtering

[](#filtering)

You can filter your post-container entities using `Request` attributes or query params :

- `tag`: Filter by a tag’ name using Roadiz nodes’s `tags` field. **You can pass an array of tag name to combine them.**
- `archive`: Filter by month and year, or just year on `publishedAt` field, or the one defined by `getPublicationField` method.
- `related`: Filter by a related node’ name using Roadiz nodes’s `bNodes` field. **You can pass an array of node name to combine them.**

### Usage

[](#usage)

All you need to do is creating your `PostContainer` node-source's `Controller` in your theme and implements `ConfigurableController` and use `PostContainerControllerTrait`. You will be able to override any methods to configure your blog listing.

```
