[5.8] - Content Block - Card Attributes #17528
-
|
Experimenting with the new Content Blocks and they're great. The one downside I see so far is that grouping fields in a Content Block means they are no longer available as card attributes. My old implementation had a "Page Header" section. These fields are available as attributes Moving to a Content Block: They are no longer available. Could content block fields be pulled up into the card attribute selector? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 6 replies
-
|
As it stands, this is correct, content block fields can't be directly used as card attributes. You can, however, use the new Generated Fields feature to pull field data from the content block and expose it to the card: (There are some limitations here, particularly with HTML; we use the "site" template mode when rendering object templates, so some CP-specific functions are unavailable.) |
Beta Was this translation helpful? Give feedback.
-
|
As an alternative to generated fields, you could expose Content Block field values using custom card attributes added in Event::on(
Entry::class,
Element::EVENT_REGISTER_CARD_ATTRIBUTES,
static function (RegisterElementCardAttributesEvent $event) {
$event->cardAttributes['_page_header_heading'] = [
'label' => Craft::t('site', 'Page Header Heading'),
'placeholder' => Craft::t('site', 'Some awesome heading'),
];
}
);
Event::on(
Entry::class,
Element::EVENT_DEFINE_ATTRIBUTE_HTML,
static function (DefineAttributeHtmlEvent $event) {
if ($event->attribute === '_page_header_heading') {
$event->html = $event->sender?->pageHeader?->heading ?? '';
}
}
); |
Beta Was this translation helpful? Give feedback.
-
|
Kinda related: #17507 Essentialy, this would enable one to display content block field values, via generated fields, in entry indices. |
Beta Was this translation helpful? Give feedback.
-
|
I was looking pretty much at the same use case as Leevi - it'd be great if your Content Block fields (specifically assets set as card thumbnails) would bubble up. The workarounds seem counterintuitive to what Content Blocks were supposed to solve in the first place. |
Beta Was this translation helpful? Give feedback.
-
|
@khalwat Solved this nicely in Seomatic. Something similar for card attributes would work. Still no solution for thumbnails. |
Beta Was this translation helpful? Give feedback.
-
|
Added this for 5.9 🎉 (#18206) |
Beta Was this translation helpful? Give feedback.




Added this for 5.9 🎉 (#18206)