Checking if code for rendering Markdown is correct for Kirby 4?

Hi,

24 hours into playing with Kirby and learning PHP from scratch!

So here’s the relevant set up:

site/config/config.php is

return [
    'debug' => true,
    'content' => [
      'extension' => 'md'
    ],
    'markdown' => [
      'extra' => true
    ],
];

And contents of content/2_articles/1_article_one is:

Title: Article One
----
Text: 

## Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Donec sodales pulvinar magna eget vulputate. In hac habitasse platea dictumst. Praesent faucibus malesuada est vel interdum. Aenean ut mauris semper lacus efficitur iaculis.

Pellentesque velit ipsum, laoreet eu accumsan sed, sodales eu nisi. Nulla hendrerit erat sed magna sollicitudin congue. Sed massa eros, fermentum id dictum eu, imperdiet ac ante. Maecenas nisl erat, consectetur quis ipsum vel, vulputate laoreet turpis. Suspendisse non nisl sed mi dapibus fringilla.

Pellentesque ac consectetur turpis. Praesent ultrices augue et ligula tempor, a interdum purus consequat. Donec sit amet dictum ipsum, vel vestibulum lectus. Vestibulum purus odio, vestibulum a mauris quis, facilisis interdum nisi. Fusce rhoncus neque non lorem euismod, eu volutpat ante consectetur. Maecenas in mollis tellus.

And I got it to work:

By following the instructions from Markdown doesn´t render:

Hence, article.php is:

<?php snippet('header') ?>

<main class="main">

    <h1><?= $page->title() ?></h1>
    
    <?= $page->text()->kt() ?>

</main>

<?php snippet('footer') ?>

Which, I note, was for Kirby 3.

I went to $page to learn more about $page->text()->kt() but was puzzled to not be able to find $page->text() there.

So wanted to check if I’m using the right code for Kirby 4 (I assume since I’m working with the most recent starterkit and plainkit, it probably is Kirby 4?) or if I should be using something else to render Markdown?

Thanks!

The code is correct. The reason there is no text method is that you define your field names in your blueprints (if you want to use the Panel), or you just add the fields in your content manually.

Additionally, $page->yourFieldName() is a shortcut for the longer version $page->content()->get('yourFieldName'). Both versions return a Kirby\Cms\Field object. the methods you can use on a Field object to manipulate the value, you can find under Field methods | Kirby CMS.

Ohhh, so text() is one of those that is named by the user… I simply copied and pasted it verbatim from the quote above and didn’t realize!

So it happened to work simply because I had Text: in content/2_articles/1_article-one/article.md, yes?

Thanks for the link, that makes more sense now!

Right.

Field names are up to you, you define what your content model needs in each case (and then you need to render these fields (or the field that you want to output in the frontend) in your templates, of course). And here are the rules for naming fields: Using fields | Kirby CMS

1 Like