I would not add the spacing with lines, but with CSS.
So you mean use this code: <div><?php echo nl2br($betten->accordionbeschreibungeins()->text()->kirbytext()); ?></div>
but decrease spacing using CSS.
As I understand you, you want to create additional spacing with <br>
.
Multiple use of <br>
in a row is not a compliant solution.
Therefore my suggestion to adjust the line spacing with CSS.
Which framework do you use for your website?
For example, if you are using Bootstrap, check here:
It worked perfectly fine. Many thanks indeed
If youâd remove the nl2br and simply use
<?= $betten->accordionbeschreibungeins()->kirbytext() ?>
you wouldnât run into the spacing issue in the first place.
I use vanilla CSS and avoid using Bootstrap. I prefer not to rely on a CSS framework as I like to craft my own components. The same applies to JavaScript although I do use jQuery when I need.
Sorry, I had to leave the workplace.
Itâs the same as <?php echo
, yes. Its part of standard PHP, so it doesnât necessarily have to be used with Kirby content. In the context of the example, however, it does, yes.
To be nitpicky, $page
is a variable pointing to a instance of a class, not the class name.
The name of the class of which it is an instance of happens to also be âPageâ, but thatâs a coincidence and not a rule. For example $betten
is also a variable pointing to another instance of the same Page
class.
yes. But the most important part is that both ends of that arrow have a meaning: youâre accessing a text()
function, but specifically itâs the text()
function of the $page
instance. Likewise, youâre accessing a kirbytext()
function, but specifically itâs the kirbytext()
function of whatever text()
has returned.
In the context of Kirby:
Page instances, like $page
or $betten
, offer a few functions which refer to the page itself (for example think ->url()
which returns a string containing the url for that page), besides those functions, every other function name you call will return an instance of class Field
. It will give you a Field instance even if the page doesnât even have contents for that field name.
On Field instances, you can call what Kirby calls âfield methodsâ (a method, in OOP lingo, is a function which is bound to an instance). kirbytext()
is a field method, specifically it takes the contents of the field instance you call it on, parses the contained markdown (FYI this is the step which adds the <br>
s), parses any Kirby tags it might contain, creates html out of it and returns a copy of the field instance which contains the created html.
So:
<?= $page->text()->kirbytext() ?>
Echoes the return value of kirbytext()
, which is called on the return value of text()
which is called on $page
.
$page
is an instance of Page
.
$page->text()
gives you an instance of the field âtextâ which is stored in the Page
$page
.
$page->text()->kirbytext()
takes that fields content, transforms it, and returns a new Field
instance which contains that transformed text.
<?= $betten->accordionbeschreibungeins()->kirbytext() ?>
Echoes the return value of kirbytext()
, which is called on the return value of accordionbeschreibungeins()
which is called on $betten
.
$betten
is an instance of Page
.
$betten->accordionbeschreibungeins()
gives you an instance of the field âaccordionbeschreibungeinsâ which is stored in the Page
instance $betten
.
$betten->accordionbeschreibungeins()->kirbytext()
takes that fields content, transforms it, and returns a new Field
instance which contains that transformed text.
Thank you very much indeed for this detailed explanation. I learned so much from you.