How to add class to kirbytext


I’m trying to add a class “paragraph” to the <p> tag when calling kirbytext:
<?= $post->text()->kirbytext() ?>

I found this solution for Kirby 2, is this still the preferred way to go or has anything changed in Kirby 3 to make this easier?

Kirby now has the kirbytextinline() method. But note that both the method and the above code remove all p tags. So it doesn’t really make sense for multi-paragraph text.

Why do you need a class on the p tag? How about wrapping the text inside a div and target the p tags inside the div via the class applied to the div?

<div class="text">
<?= $post->text()->kirbytext() ?>
.text p {
  /* styles */

Best solution depends on your use case.

1 Like

Thanks that makes sense!