PHPackages                             heimrichhannot/contao-reader-bundle - 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. heimrichhannot/contao-reader-bundle

ActiveContao-bundle

heimrichhannot/contao-reader-bundle
===================================

This bundle offers a generic reader module to use with arbitrary contao entities containing standard reader specific functionality like field output, images and auto\_item handling.

1.42.5(1y ago)35.1k2[3 issues](https://github.com/heimrichhannot/contao-reader-bundle/issues)[1 PRs](https://github.com/heimrichhannot/contao-reader-bundle/pulls)3LGPL-3.0-or-laterPHPPHP ^7.4 || ^8.0CI failing

Since Feb 27Pushed 1y ago4 watchersCompare

[ Source](https://github.com/heimrichhannot/contao-reader-bundle)[ Packagist](https://packagist.org/packages/heimrichhannot/contao-reader-bundle)[ RSS](/packages/heimrichhannot-contao-reader-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (33)Versions (206)Used By (3)

Contao Reader Bundle
====================

[](#contao-reader-bundle)

[![](https://camo.githubusercontent.com/3fafa68bd0896c467a3d5ccec7ed144c308e84ec13afa86e8313c628b30d5065/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6865696d7269636868616e6e6f742f636f6e74616f2d7265616465722d62756e646c652e737667)](https://camo.githubusercontent.com/3fafa68bd0896c467a3d5ccec7ed144c308e84ec13afa86e8313c628b30d5065/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6865696d7269636868616e6e6f742f636f6e74616f2d7265616465722d62756e646c652e737667)[![](https://camo.githubusercontent.com/62a69c2e8e4b10573f47ea69db6924b56de1cf29d90a52d73df2cdad65fe0273/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6865696d7269636868616e6e6f742f636f6e74616f2d7265616465722d62756e646c652e737667)](https://camo.githubusercontent.com/62a69c2e8e4b10573f47ea69db6924b56de1cf29d90a52d73df2cdad65fe0273/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6865696d7269636868616e6e6f742f636f6e74616f2d7265616465722d62756e646c652e737667)[![Build Status](https://camo.githubusercontent.com/18db82969be3b1673341ef430201a377a57c79d24c5be7a88ca046e1fcbc824c/68747470733a2f2f7472617669732d63692e6f72672f6865696d7269636868616e6e6f742f636f6e74616f2d7265616465722d62756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/heimrichhannot/contao-reader-bundle)[![Coverage Status](https://camo.githubusercontent.com/e26e549f0f04879b67653d0221edb2cd414e71f907cd0a29135b06bad5995ea4/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6865696d7269636868616e6e6f742f636f6e74616f2d7265616465722d62756e646c652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/heimrichhannot/contao-reader-bundle?branch=master)

This bundle offers a generic reader module to use with arbitrary contao entities containing standard reader specific functionality like field output, images and auto\_item handling.

It makes it possible to generate readers not only for events, news or faq's but with every DCA you like.

Features
--------

[](#features)

- generic reader module: output entities of arbitrary DCA entities
- dedicated and inheritable reader config entities that can be assigned to one or many modules
- twig support for templates
- [Head Bundle](https://github.com/heimrichhannot/contao-head-bundle) support

*Hint: This module can greatly be used with [heimrichhannot/contao-list-bundle](https://github.com/heimrichhannot/contao-list-bundle) which can display lists of arbitrary DCA entities*

Impressions
-----------

[](#impressions)

### Reader configuration

[](#reader-configuration)

[![alt preview](docs/reader-config.png)](docs/reader-config.png)

Concepts
--------

[](#concepts)

### Inheritable reader configuration

[](#inheritable-reader-configuration)

Since reader configuration can be lots of data sometimes we decided to outsource it into a dedicated DCA entity. These entities can be assigned to one or even multiple reader modules in a reusable way.

In addition it's possible to create reader configs that inherit from other reader configs. Hence overriding a single option while keeping everything else is possible.

### The Item class

[](#the-item-class)

Every database record output in a reader (e.g. an event) is modelled and wrapped by the `Item` class. The concrete class is `DefaultItem`. You can imagine the item as a kind of ORM (object-relational-mapping).

The most important properties of an item are the arrays `raw` and `formatted` which also can be iterated in the reader item template:

- `raw`: contains the raw database values
- `formatted`: contains the formatted representation of the raw values

Example: Let's say a database record has a field `startDate` which holds a unix timestamp of the date chosen in the backend. Then `raw` contains this unix timestamp and `formatted` contains the pretty printed date according to the `dateFormat` set in the contao settings, i.e. "2020-09-12".

The reader bundle uses the method `FormUtil::prepareSpecialValueForOutput()` in [heimrichhannot/contao-utils-bundle](https://github.com/heimrichhannot/contao-utils-bundle)for handling special values. It supports a wide range of types of special values:

- date/time fields
- arrays
- fields with `options`, `options_callback` and entries in the DCA's `reference` key
- binary fields (files, images, ...)
- ...

You can access both of these arrays in your reader item twig template as you normally would in twig:

```
{% for field, value in raw %}
{% endfor %}

{% for field, value in formatted %}
{% endfor %}
```

**CAUTION:** By default all values of a database record are formatted and accessible in the item template. As you can imagine if some of the fields have thousands of options, the process of formatting can take some time and can reduce the peformance of your website. **Hence you always should limit the formatted fields and only format these you really need.** You can adjust that in the reader configuration (field `limitFormattedFields`).

For convenience reasons you can also access the field values like so in your twig template:

```
{{ fieldname }}
```

If you configured the field `fieldname` to be formatted, it will contain the formatted value. If not, the raw one. If it's formatted, you can still access its raw value by using:

```
{{ raw.fieldname }}
```

### Reader config elements

[](#reader-config-elements)

Every reader config can have one or more reader config elements. These are designed to specify things that can occur multiple times (e.g. because there are many fields of one type).

Currently build-in reader config element types:

TypeDescriptionimageConfigure the output of one or more image fields separately (image size, placeholder handling, ...)tagsOutput one or more tag fields based on [codefog/tags-bundle](https://github.com/codefog/tags-bundle).related itemsOutput related items based on given tags (needs [heimrichhannot/contao-list-bundle](https://github.com/heimrichhannot/contao-list-bundle); needs [codefog/tags-bundle](https://github.com/codefog/tags-bundle)) or categories (needs [heimrichhannot/contao-categories-bundle](https://github.com/heimrichhannot/contao-categories-bundle)).Other bundle can add reader config elements as well. Some examples:

- [Syndication through Syndication Type Bundle](https://github.com/heimrichhannot/contao-syndication-type-bundle)
- [Enhanced Videos through Video Bundle](https://github.com/heimrichhannot/contao-video-bundle)

#### Image

[](#image)

You can add images either as formatted value of, if you also like to have additional features like image size processing or automatic placeholders if no image is set, you can use the *image reader config element*.

After the configuration you can output it as follows in your item template:

```
{% if images|default and images.myImage|default %}
    {{ include('@HeimrichHannotContaoUtils/image.html.twig', images.myImage) }}
{% endif %}
```

**IMPORTANT:** Note that by default the generated picture elements are added to an array called `images`. If your DCA contains a field with the same name, you need to specify a different container name like e.g. `resizedImages`(using `overrideTemplateContainerVariable`).

### Templates

[](#templates)

There are two ways to define your templates.

#### 1. By Prefix

[](#1-by-prefix)

The first one is to simply deploy twig templates inside any `templates` or bundles `views` directory with the following prefixes:

- `reader_item_`
- `item_`
- `news_`
- `event_`

**More prefixes can be defined, see 2nd way.**

#### 2. By config.yml

[](#2-by-configyml)

The second on is to extend the `config.yml` and define a strict template:

**Plugin.php**

```
