One of three fields not displayed

Dear community,

the website I work on currently includes a cute little news section with title, date and content, but only the first two are displayed.

YML

title: News
fields:
  news:
    type: structure
    label: News Items
    fields:
      date:
        type: date
        label: Date
      title:
        type: text
        label: Title
      content:
        type: textarea
        label: Content

PHP

<div class="news-section">
    <?php
    $newsPage = page('news');

    if ($newsPage && $newsPage->news()->isNotEmpty()) {
        $newsItems = $newsPage->news()->toStructure();
        ?>

        <div id="news-items-container">
        <p > +++ PUSH NEWS +++ </p>
        <br> </br>
            <?php foreach ($newsItems as $newsItem): ?>
                <div class="news-item">
                    <div class="news-header">
                        <span class="news-date"><?= $newsItem->date()->toDate('d M Y') ?></span>
                        <h3 class="news-title"><?= $newsItem->title() ?></h3>
                    </div>
                    <div class="news-content">
                      <p><?= $newsItem->content()->text()?></p>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    <?php
    
    } else {
        echo '<p>No news available.</p>';
    }
    ?>
</div>

when debugging with
<?= var_dump($newsItem->content()) ?>

the news page loads

object(Kirby\Content\Content)#253 (3) { [“date”]=> string(10) “2025-01-01” [“title”]=> string(32) “Residency at Clay Club Den Bosch” [“content”]=> array(5) { [0]=> string(40) “To broaden my practice, I am diving into” [1]=> string(40) “the world of clay, and level my practice” [2]=> string(30) “up to new heights. The journey” [3]=> string(39) “continues. Looking forward to tell you,” [4]=> string(10) “more soon.” } }

I’ve tried several different methods to retrieve the content, such as using kt() , value() , and others, but the content field remains empty when displayed on the page, even though it contains text in the backend.

It got me stuck for a while now and I would appreciate your help a lot!

The problem is that content is a reserved name, i.e. there is a native method content on the StructureObject ($structureobject->content() | Kirby CMS).

You can either give your field another name, or call it via the content() object, instead of

<?= $newsItem->content()->text()?>

use

<?= $newsItem->content()->get('content') ?>

Also, there is no such thing as a text() field method, or is that some custom code? If not, what are you trying to achieve with calling text() on the content() field?

Thank you Sonja, its working now! super cool.
It didn’t function just like that but with some extra polishing it did, with help of GPT (noob alert)

 <div class="news-content">
                    <p>
                    <?php 
                    $content = $newsItem->content()->get('content');
                    if (is_array($content)) {
                        echo implode(' ', $content);
                    } else {
                        echo $content;
                    }
                    ?>
                </p>
                    </div>