Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AManInYorkshire's avatar

Nova Table Metric - HTML in title

All,

I have created a table metric and would like to link to a resource from the title of each entry in the table.

I currently have a calculate function that looks like this:

    public function calculate(NovaRequest $request)
    {
        $leagueSeasons = LeagueSeason::where('start_date','>=',Carbon::now()->startOfDay())
            ->whereRelation('league','active',true)
            ->orderBy('start_date')
            ->get();

        return $leagueSeasons->map(function($ls) {
            $url = route('nova.pages.detail',['resource' => 'league-season','resourceId' => $ls->id]);
            return MetricTableRow::make()
                    ->icon('clock')
                    ->iconClass('text-gray-400')
                    ->title("<a href='$url'>{$ls->getDescription()}</a>")
                    ->subtitle($ls->start_date->format('l jS F Y'));
        })->toArray();
    }

However, the HTML in the title of the MetricTableRow is escaped.

Any thoughts on how I could do this?

:wq

0 likes
2 replies
krisi_gjika's avatar
Level 14

Create a MenuItem action on your TableMetricRow

AManInYorkshire's avatar

@krisi_gjika super, thank you, that worked. Ideally I would have liked to be able to create a link in the title, to avoid having to use the action button, but it works and is easy to implement. Perhaps the ability to include HTML in the title and subtitle may come another time. For reference, my code now looks like this:

    public function calculate(NovaRequest $request)
    {
        $leagueSeasons = LeagueSeason::where('start_date','>=',Carbon::now()->startOfDay())
            ->whereRelation('league','active',true)
            ->orderBy('start_date')
            ->get();

        return $leagueSeasons->map(function($ls) {
            $url = route('nova.pages.detail',['resource' => 'league-seasons','resourceId' => $ls->id],false);
            return MetricTableRow::make()
                    ->icon('clock')
                    ->iconClass('text-gray-400')
                    ->title("{$ls->getDescription()}")
                    ->subtitle($ls->start_date->format('l jS F Y'))
                    ->actions(function() USE ($url) {
                        return [
                            MenuItem::link('View',$url)
                        ];
                    });
        })->toArray();
    }

:wq

Please or to participate in this conversation.