Kirbytext wraps everything in `<p>`

panel
#1

The Kirbytext method wraps everything in <p> tags. I want to get rid of the

tags but if I tried ktRaw of html it not used my enters form my field in the text.

Does anybody know how to fix this?

Thanks!

#2

There is a kirbytextInline() method, but that only makes sense for single line text, not for multiline text from a textarea field.

What is your use case? Please be more specific what your problem is.

#3

I have two sentences with an enter in between. I can split it into 2 fields but that’s a bit cumbersome.

#4

What is your expected result? And if you don’t want the p-tags, why do you put an “enter” in between? That is standard markdown behaviour.

1 Like
#5

I know it is the standard markdown behaviour but I want to make use of the enters in my panel field but not the p tags. With ktRaw and html I looses the enters from my field.

Do I have to do inline styling?

Thanks

#6

Oh! I think if I add an class to my code:

<?php echo $page->headlinequote()->kirbytext() ?>

Edit: yes that works out! Thanks @texnixe

#7

I converted the K2 kirbytextraw plugin for Kirby 3:

<?php
/*
 * kirby 3 plugin - kirbytextRaw
 * parse text as kirbytext but remove the p tags
 *
 * copyright: Jannik Beyerstedt | http://jannikbeyerstedt.de | code@jannikbeyerstedt.de
 * license: http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 License
 * v1.0.1 (27.11.2014)
 *
 * Sample Usage:
 * <?php echo $page->text()->kirbytextraw() ?>
 */

function kirbytextRaw($content) {
  $text = kirbytext($content);
  return preg_replace('/(.*)<\/p>/', '$1', preg_replace('/<p>(.*)/', '$1', $text));
}

Kirby::plugin('bvdputte/kirbytextraw', [
    'fieldMethods' => [
        'kirbytextraw' => function($field) {
          return kirbytextRaw($field->value);
        }
    ]
]);
1 Like
#8

Thank you! appreciate it :slight_smile:

#9

@bvdputte I copied your code and followed the plugin documentation (https://getkirby.com/docs/guide/plugins/plugin-basics) but don’t get it working.

I have copied this code and made index.php inside a plugin folder named kirbytextraw. Do I have to do something else?

Thanks!

#10

You have to also call $page->fieldname()->kirbytextraw() instead of $page->fieldname()->kirbytext().

Or do you actually get an error message?

#12

Oh shame on me. I made a typo! :sweat_smile:

Thanks!