DefineCard Event
For anything a template can't do:
PHP
use bensomething\placard\events\DefineCardEvent;
use bensomething\placard\services\Generator;
use yii\base\Event;
Event::on(Generator::class, Generator::EVENT_DEFINE_CARD, function (DefineCardEvent $e) {
if ($e->entry->section?->handle === 'home') {
$e->title = 'My Brand';
$e->label = '';
}
});
The event has title, label, description, meta, backgroundImage and backgroundColor, plus the card's resolved settings, which can be changed for that card alone. An empty value drops that element.
Per site #
There are no per-site settings in the config yet, but the event can change a card's settings by the entry's site. setAttributes() takes the same keys as config/placard.php, and its false lets it set any of them:
PHP
Event::on(Generator::class, Generator::EVENT_DEFINE_CARD, function (DefineCardEvent $e) {
if ($e->entry->getSite()->handle === 'fr') {
$e->settings->setAttributes([
'background' => '#002395',
'title' => ['googleFont' => 'Fraunces'],
], false);
}
});
Use the entry's site rather than the current one, as cards are also drawn by queue jobs and placard/generate, outside the site's own requests.