->toStructure() help

Hi guys,

Any help, I cannot seem to understand where I went wrong, or what I need to do:

<?= $service->content() ?> doesnt seem to work

<ul>
          <?php foreach ($page->myServices()->toStructure() as $service): ?>
          <li>
            <h3><?= $service->title() ?></h3>
            <?= $service->content() ?>
          </li>
          <?php endforeach ?>
        </ul>

I get this error:

Whoops \ Exception \ ErrorException (E_RECOVERABLE_ERROR)
Object of class Kirby\Cms\Content could not be converted to string

Thanks

Could you post your blueprint (or the part relating to the structure field) please?

Sorry, yes here it is:

# Services Section
      services:
        width: 1/1
        sections:
          services:
            type: fields
            fields:

              servicesSection:
                label: Services Section
                type: headline
                numbered: false

              myServices:
                label: My Services
                type: structure
                fields:
                  title:
                    label: Service
                    type: text
                  content:
                    label: Description
                    type: textarea

Try

<?= $service->content()->get('content')->kt() ?>

Brilliant, it works!

Just to further my knowledge, may I ask why i need ->get()?

How come it doesnt work without like the h3 title? Thanks!

In general, it is recommended to use field names other than Kirby native methods. If you use them nevertheless, you have to go via the content() object. See docs: Fields | Kirby CMS

1 Like

Makes sense, thank you very much!