You’ll need to modify your template so that it outputs both the attribute name and value. Right now, your code only retrieves and displays the attribute value.
Modify your loop inside the div class=“ccm-block-calendar-event-attributes” so it also outputs the attribute name.
<?php if (count($displayEventAttributes)) { ?>
<div class="ccm-block-calendar-event-attributes">
<?php foreach ($displayEventAttributes as $akID) {
$ak = EventKey::getByID($akID);
if (is_object($ak)) {
$attributeName = $ak->getAttributeKeyDisplayName(); // Gets the attribute name
$attributeValue = $event->getAttribute($ak->getAttributeKeyHandle(), 'display'); // Gets the value
if (!empty($attributeValue)) { // Only display if there is a value
echo '<p><strong>' . h($attributeName) . ':</strong> ' . h($attributeValue) . '</p>';
}
}
} ?>
</div>
<?php } ?>
So
getAttributeKeyDisplayName()
:
Retrieves the readable name of the attribute.
getAttribute()
: Fetches the attribute’s value.
h()
: Escapes output for security.
Conditional Check (if (!empty($attributeValue))
): Ensures only attributes with values are displayed.