Line breaks and text formatting issues

Hi there,

I have a reccurent kind of difficulties concerning linebreaks.

For the exact same field content that you can see above, here are the different renders :

<?= $page->intro()->kt() ?>
Kirby text : list-style ok but line breaks ignored.

<?= $page->intro()->kti() ?>
Kirby text inline ->kti() : line breaks ok but list-style ignored

<?= $page->intro()->markdown() ?>
Markdown ->markdown() : line breaks ok but list-style ignored

<?= $page->intro()->kti()->markdown() ?>
Kirbytext inline then markdown: list-style ok but too much
added for each line break,

  • correctly closed and empty paragraphs

    <?= $page->intro()->markdown()->kti() ?>
    Markdown then Kirbytext : perhaps the cleanest solution but there is still an unwanted
    between the

  • tags and extra empty

    tags:


    Any idea ?

    Thanks for your help

  • What is your expected output? Why do you want additional br tags? The correct way to render your content is with simply using kirbytext() not in combination with anything else.

    Thanks for your answer.

    For my client, I want the front-end to behave as close as possible to the render of the text in the panel :
    carriage return in the panel -> carriage return in the front-end
    line break in the panel -> line break in the front-end

    Line feeds work by adding three spaces after a line (or enabling markdown breaks), but not between block elements. It’s not a good idea to enforce margins by adding line breaks, anyway.

    Bildschirmfoto 2020-07-13 um 15.05.22

    Ok I fixed it without using nothing else than kirbytext.

    Thanks @texnixe

    Hi,
    I will just extend the question a bit by:

    Is it possible to get a version of text through kirbytext() that doesn’t contain actual line-breaks in the code so I can use it for Jquery?

    I want to use it like in the upper part of the picture.
    but it always turns out to look like in the lower part of the picture when I check the web inspector, the code is disturbed and it won’t work…

    any smooth and official ways to do it?

    Thx for help

    If I understand you correctly, you want to remove line breaks that are actually present in the content?

    yes exactly, but I would like to keep the html tags kirbytext() gives me.

    The I’d remove those linebreaks via str_replace() or Kirby’s Str::replace() method.

    Great, it worked! Had been breaking my head over it too long for this simple answer.
    Thanks a lot!

    I guess it is part of this conversation but what I’m trying to do is the following:

    • I enter a text in my CMS.
    • I want the paragraph space to be respected according to the edit and not appear as inline text.
    • I want that each paragraph to be marked as <p>.

    This is the current situation.


    Thanks!

    Are you rendering your field with kirbytext() in your template?

    Honestly, I’m not sure but I don’t think so.

    You have to render textarea fields with the kirbytext() method.

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

    Then it will render with the p tags etc.

    On a side note, it helps tremendously, if you post code as code snippets instead of screenshots, like this:

    three-backticks-800x

    Thanks!

    You are right, next time I will post it as code. Sorry!