Helpers Reference
app/Helpers/cms_helper.php is loaded globally by CI4's autoloader (configured in app/Config/Autoload.php). All functions are available in controllers, models, views, and plugin code without any helper() call.
active_theme(): ?object
Returns the currently active theme record from the themes table, or null if no theme is active.
$theme = active_theme();
if ($theme) {
echo $theme->name; // e.g. "Ember"
echo $theme->folder; // e.g. "ember"
}
Also available as service('theme')->getActive().
widget_area(string $slug): string
Renders all widget instances assigned to the named area and returns the HTML string.
echo widget_area('sidebar');
echo widget_area('footer-1');
This is the PHP-side equivalent of the {! widget_area "slug" !} tag function in templates.
theme_url(string $path = ''): string
Returns the public URL to a file in the active theme's directory.
$css = theme_url('theme.css');
// https://example.com/themes/ember/theme.css
site_name(): string
Returns the configured site name from settings (App.siteName).
$title = site_name() . ' | Blog';
site_tagline(): string
Returns the configured site tagline from settings (App.siteTagline).
post_url(string $slug): string
Returns the public URL for a post with the given slug.
$url = post_url('my-first-post');
// https://example.com/post/my-first-post
category_url(string $slug): string
Returns the public URL for a category archive with the given slug.
$url = category_url('news');
// https://example.com/category/news
tag_url(string $slug): string
Returns the public URL for a tag archive with the given slug.
$url = tag_url('php');
// https://example.com/tag/php
render_content(object $entity): string
Runs a post or page entity through the full content rendering pipeline. Applies shortcode processing, markdown rendering (if applicable), and returns sanitised HTML.
$html = render_content($post);
echo $html; // already safe HTML, do not double-escape
The $entity must be a full object with at minimum body and format properties.
excerpt(string $text, int $length = 150): string
Strips HTML tags from $text, truncates to $length characters at a word boundary, and appends ... if truncated.
$summary = excerpt($post->body, 200);
slug_from_title(string $title): string
Converts a title string to a URL-safe slug: lowercased, spaces to hyphens, non-alphanumeric characters stripped.
$slug = slug_from_title('Hello, World! My First Post');
// hello-world-my-first-post
Useful in admin controllers when auto-generating slugs from post/page titles.