The “teaser_selection” content type is used for displaying teasers to other
content in your website. These teasers could be arranged as list or grid, like
in this example:
In the administration interface, the widget is displayed as a selector for the
teasers. Content managers can choose a number of target contents. By default,
the text from the “Excerpt & Categories” tab of the target content is shown.
You can however customize the text of the teaser if you like.
The following parameters can be used to customize the field in the page template:
Parameter
Type
Description
present_as
collection
A collection of strings. Each string is typically a CSS class that is
used to render the teaser list. You can configure the <title> of
each entry that is shown in the admin
Sometimes, a content manager wants to control exactly how a list of teasers
is presented. You can plan for different rendering variants in your design and
let the content manager choose one variant in the administration interface.
Use the present_as option to configure the rendering variants:
If you want to display teasers of custom data, create an implementation of
TeaserProviderInterface. For example, we’ll make it possible to select
from a list of recipes:
<?phpnamespaceAppBundle\Teaser;useSulu\Bundle\PageBundle\Teaser\Configuration\TeaserConfiguration;useSulu\Bundle\PageBundle\Teaser\Provider\TeaserProviderInterface;useSulu\Bundle\PageBundle\Teaser\Teaser;classRecipeTeaserProviderimplementsTeaserProviderInterface{/** * Returns the configuration for rendering the teaser provider in the * administration interface * * @return TeaserProvider */publicfunctiongetConfiguration(){returnnewTeaserConfiguration('Recipe',// The title in the dropdown of the administration interface'recipes',// The resourceKey of the entities to load for this type of teaser'table',// The list adapter in which the entities should be shown['title'],// The properties which should be shown'Recipe',// The title of the overlay that shows when this entity is assigned'app.recipe_edit_form',// The view to which a click on an item in the Admin UI will navigate (optional)['id'=>'id'],// The mapping of the teaserItem to the path parameters of the above view (optional));}/** * Returns the actual teaser data. * * @return Teaser[] The teasers */publicfunctionfind(array$ids,$locale){if(0===count($ids)){return[];}$items=...;// load items by idforeach($itemsas$item){$result[]=newTeaser(...);}return$result;}}
Register the provider in Symfony’s service container and tag it with
sulu.teaser.provider to make it functional: