$field->toStructure()

Converts a yaml field to a Structure object

  • return ($structure)

While the yaml method returns a simple associative PHP array for structured field content, the toStructure method gives you a full blown Kirby Collection which makes it possible to use Kirby's chaining syntax.

Example

Text file

title: My page
----
Accounts:
- name: Twitter
  url: http://twitter.com/getkirby
- name: Github
  url: http://github.com/getkirby

Template

<h1>On the web</h1>
<ul>
  <?php foreach($page->accounts()->toStructure() as $account): ?>
  <li>
    <a href="<?php echo $account->url() ?>">
      <?php echo $account->name()->html() ?>
    </a>
  </li>
  <?php endforeach ?>
</ul>