Vimeo Videotitle doesn't work

Hi guys,

I’ve got a structure, which contains vimeo links and the fitting title to each of it.
Of course I want to display the title above each video. Here is my code and the error I’m receiving.

<?php foreach($data->vimeolinks()->yaml() as $vimeovid): ?>
  <?= $vimeovid->titel()->html() ?>
  <?php echo vimeo($vimeovid['vimeoid']) ?>
<?php endforeach ?>

This is the blueprint:

  vimeolinks:
    label: Videos
    type: structure
    style: table
    fields:
      titel:
        label: Titel - Video
        type: text
      vimeoid:
        label: Link (URL)
        type: text

I’m getting error: “Call to a member function titel() on array”.

I can’t figure out why it is not working. The structure is on a one-pager btw.

To fetch a structure. field, there are two methods:

  • yaml(): gives you an array
  • toStructure(): gives you a collection.

If you have a collection, you can use arrow syntax like in your title example above

<?php foreach($data->vimeolinks()->toStructure() as $vimeovid): ?>
  <?= $vimeovid->titel()->html() ?>
  <?php echo vimeo($vimeovid->vimeoid()) ?>
<?php endforeach ?>

If you use yaml(), however, you have to get the subfields like this (and like you do it for the vimeoid:

<?php foreach($data->vimeolinks()->yaml() as $vimeovid): ?>
  <?= $vimeovid['title'] ?>
  <?php echo vimeo($vimeovid['vimeoid']) ?>
<?php endforeach ?>

So. it’s either-or, not mix.

1 Like