How can I store "virtual fields" in a block

Hi there,

On my page I am using blocks and in a controller on a certain page I need to do some parsing for each block and store the parsed values within the block somehow to later use it in my template. I have no idea how to properly do this.

Ideally I would like to set it up in a way, so I can use it like this in my template:

<?php foreach ($blocks as $block): ?>
  <p>My parsed value: <?= $block->parsedValue() ?></p>
<?php endforeach ?>

where parsedValue() is a virtual field, i.e. a field that does not exist in the block’s blueprint.

Can anyone help me achieve this?

Thanks a lot!
trych

There is no such thing as custom block methods at the moment, but you could use standard functions.

function parsedValue($block) {
  // do stuff with the block
  return 'something';
}
<?= parsedValue($block); ?>

Not as nice as a method, but better than nothing.

Thanks, @pixelijn, I will look into doing it like this.