Kirby editor field – access attributes array

Hi! Is there an in-built possibility to access the attrs[] array of the editor field? I know there’s the attrs(), however I’m not sure on how to use it https://github.com/getkirby/editor/wiki/Block-object

I’m trying to get the src element of the editor field’s array in

Covervideo:
[
  {
    "attrs": {
        "src": "https://vimeo.com/example",
        "caption": ""
    },
    "content": "",
    "id": "_0z7rixs4n",
    "type": "video"
  }
]

I tried $page->covervideo()->attrs()->src() but I guess this isn’t how the attr() is supposed to be used.

Foreach-looping $page->covervideo()->attrs() as $attr returns the whole array (as string, I guess) instead of single elements.

Do I have to access it via JSON?

Thanks for any tips!

But you already link to the correct resource: https://github.com/getkirby/editor/wiki/Block-object#block-attrs, so for example:

<?= $block->attrs()->src() ?>
1 Like

I thought so too, but <?= $page->covervideo()->attrs()->src() ?>
returns

[
{
"attrs": {
    "src": "https://vimeo.com/example",
    "caption": ""
},
"content": "",
"id": "_0z7rixs4n",
"type": "video"
}
]

and <?= $page->covervideo()->blocks()->attrs()->src() ?> returns an on null error

This works, but is it supposed to work like that, or is it kind of too much?

<?php  foreach(json_decode($page->covervideo()->attrs(), true) as $attrs): ?>
   <?= $attrs["attrs"]["src"] ?>
<?php endforeach ?>

An editor field consists of multiple blocks:

$blocks = $page->nameOfField()->blocks();
foreach ($blocks as $block) {
  dump($block->attrs());
}
1 Like

Thx!