Announcements Module
Announcements Module
The Announcements module does more than provide a public announcements listing at
/announcements. The latest featured announcement can also be integrated directly into another page or Module view, allowing important site notices to appear where visitors are most likely to see them.A common use is displaying the latest announcement on the site's front page.
Displaying the Latest Announcement
When
featured_announcement is available in the view data, the following can be used to render the announcement:<?php
$featuredAnnouncement = $data['featured_announcement'] ?? false;
?>
<?php if (is_array($featuredAnnouncement)): ?>
<section id="latest-announcement">
<h2>
<?= htmlspecialchars(
(string) ($featuredAnnouncement['title'] ?? ''),
ENT_QUOTES,
'UTF-8'
); ?>
</h2>
<div>
<?= (string) ($featuredAnnouncement['rendered_body'] ?? ''); ?>
</div>
<?php if (!empty($featuredAnnouncement['created_at'])): ?>
<p>
<small>
Posted:
<?= htmlspecialchars(
date(
'Y.m.d',
strtotime(
(string) $featuredAnnouncement['created_at']
)
),
ENT_QUOTES,
'UTF-8'
); ?>
</small>
</p>
<?php endif; ?>
</section>
<?php endif; ?>
This creates a simple announcement block containing the announcement title, rendered content, and publication date.
Because the announcement body is supplied as
rendered_body, content authored using the Announcements module's supported content format can be presented as already-rendered output while the title and generated date remain escaped for safe presentation.Presentation
The Announcements module provides the announcement data; presentation remains the responsibility of the site or Theme.
The
#latest-announcement section can therefore be styled to match the site's existing design without requiring the Announcements module to dictate how featured announcements should look.For example, a site may present the latest announcement as a notice, card, banner, highlighted section, or other prominent element on its front page.
The result is a single announcement managed through the Announcements module that can serve both the public
/announcements listing and other appropriate areas of the website.