Getting the first tag

Hello,

With the example below in mind, do you know how I might get the first tag in a field with a comma separated list of tags? The methods that I thought would work are giving me errors that I’m struggling to solve.

Thank you for your time

<h2>Tags</h2>
<ul>
  <?php foreach ($page->tags()->split(',') as $tag): ?>
  <li><?= $tag ?></li>
  <?php endforeach ?>
</ul>

This returns a simple indexed array, so to get the first array element:

$tag = $page->tags()->split(',')[0] ?? null;
1 Like

Thank you very much! I really appreciate your help :slight_smile:

Alternative approach just for the sake of completeness is this one

A::first($page->tags()->split(','))