Homepage
Main navigation
Main content
Additional information
October Tricks
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
October CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
By default, blog posts enable you to use a featured image, but only if you upload your image directly. If you're looking to use the Media Manager for your featured images, all it requires is making a small plugin. ```php <?php namespace Acme\BlogBanner; use System\Classes\PluginBase; use Event; /** * Class Plugin * * @package Acme\BlogBanner */ class Plugin extends PluginBase { public $require = ['RainLab.Blog']; /** * @inheritdoc */ public function pluginDetails(): array { return [ 'name' => 'Blog Banner', 'description' => 'A RainLab.Blog extension adding banner image via Media Manager to posts.', 'author' => 'Acme', 'icon' => 'icon-file-image-o', ]; } public function register() { Event::listen('backend.form.extendFields', function (\Backend\Widgets\Form $formWidget) { if (!$formWidget->getController() instanceof \RainLab\Blog\Controllers\Posts) { return; } if (!$formWidget->model instanceof \RainLab\Blog\Models\Post) { return; } $formWidget->addSecondaryTabFields([ 'metadata[banner_image]' => [ 'tab' => 'rainlab.blog::lang.post.tab_manage', 'label' => 'Banner Image', 'type' => 'mediafinder', 'mode' => 'image' ], ]); $formWidget->removeField('featured_images'); }); } } ``` Here, we call it `banner_image` instead of `featured_image` to avoid any conflicts, but that's all you need to enable the Media Manger for blog posts. To use the image in the CMS pages, just use: ```twig <img src="{{ post.metadata.banner_image|media }}"> ```
References
Add additional online resources to your trick
×
Name
URL
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline