HTML support in navigation labels, group gabels, and tenant names

HTML support in navigation labels, group gabels, and tenant names

  • html
  • navigation
  • resource
  • tenancy
PR #20685 by @danharrin

Navigation item and group labels, page and resource navigation label getters (getNavigationLabel(), NavigationItem, and NavigationGroup labels), and tenant names (getFilamentName()) can now return an Htmlable, such as an HtmlString. Plain strings are still shown as text.

E.g. show the tenant's plan in bold next to its name in the tenant menu:

public function getFilamentName(): string | Htmlable
{
  return new HtmlString(e(this->name).'<strong>'.e(this->plan).’</strong>');
}

Only Htmlable labels are rendered as trusted HTML. You must escape any dynamic content using e() before including it in an HtmlString.

For navigation groups, the array key is still the group's name, as in 'Shop' => NavigationGroup::make(new HtmlString(...)). Set $navigationGroup on your resources to 'Shop' (or an enum case), not the HTML version.

All Filament Up To Date tips