Kirbytext and nl2br

Hi,

I have a text like:

"Lorem ipsum dolor sit amet, **consectetur** adipiscing elit, sed do eiusmod tempor incididunt ut 
labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
consequat. "

and I want that it is displayed exactly like this. Normally I would use nl2br()->kirbytext()
but if i use some kirby text at the end of a line i always get to empty lines instead of one.

My field text:

Lorem **Ipsum** 
<https://google.com>
(link: https://google.com text: Google)

my code

<?= $page->text()->nl2br()->kirbytext()?>

I also tried:

<?= $page->text()->kirbytext()->nl2br()?>

The Result:

Lorem Ipsum

https://google.com

Google

What is the expected result from those 3 lines?

Lorem Ipsum
https://google.com
Google

In the field, I don’t have empty lines between the lines in the result I get them.

If I use

<?= $page->text()->kirbytext()?>

and have content in this field like:

Lorem

ipsum

the result is:

Lorem
ipsum

but it should be:

Lorem

ipsum

This is the HTML I get from those three lines when calling $page->text()->kirbytext() only:

<p>Lorem <strong>Ipsum</strong><br>
<a href="https://google.com">https://google.com</a><br>
<a href="https://google.com">Google</a></p>

Bildschirmfoto 2020-04-28 um 08.02.48

Why do you need nl2br()? here? I’ts not supposed to be used in conjunction with kirbytext():

$field->nl2br() : A shortcut for PHP’s built-in nl2br() -function, with the optional $xhtml parameter set to false ( true by default). Use case: there’s often a need for multiline-fields without parsing Kirbytext, e.g. for usage in headlines, subtitles etc. It’s way more convenient to use Kirby’s chainable API (e.g. <?= $page->subtitle()->html()->nl2br() ?> ), than to write <?= nl2br($page->subtitle()->html(), false) ?> .
Feature/fresh html helper methods by fabianmichael · Pull Request #2190 · getkirby/kirby · GitHub

1 Like

:zipper_mouth_face: :man_facepalming: :man_facepalming:t2: :man_facepalming:t3: :man_facepalming:t4: :man_facepalming:t5: :man_facepalming:t6: :zipper_mouth_face:
Oh, my goodness. Sorry, newbie mistake.
I haven’t seen the <p> tags. I didn’t define the margin of the <p>'s in my CSS, so I thought kirbytext() doesn’t care about my new paragraphs.