Kirbytext filter send array to page controller

is it possible to send the result of a kirbytext filter (eg an array) to a page controller?

my use case is to scan the text of the page, collect all values inside a specific html tag and print those values in the sidebar of the page (and then do other things…).

what would you suggest to do?

Something similar as explained here probably: Tagging URL --> Summary Page

If you need to get this from the rendered HTML rather then the markdown, the general procedure should be similar.

thank you!

with the approach you showed and by reading the code, am i wrong or i can simply output the array list in the template as-is? eg without deciding how to use it inside the template file? or is there a way to pass it as an argument to the template?

In the example, I use a page method stored in a plugin file, so

$page->whateveryoucallthemethod()

will return the result array, which you can use in your template as is.

Or you store the return value in a variable in your controller and pass that variable to your template.

perfect, thank you! did not catch that at first.

im having problems using the page method with kirby builder. it’s working with a normal field part of the page (eg. $page->text()).

my template

<?php foreach($page->builder()->toStructure()->filterBy('_fieldset', 'textblock') as $tx): ?>
  <?= $tx->text()->terms() ?>
<?php endforeach ?>

terms() is my page-method. this is only printing out the raw text of the field right now.

this is the page-method i used for a “normal” page-field. i’m collecting words surrounded by the markdown code syntax of double backticks “`”

page::$methods['terms'] = function($page) {
  preg_match_all('!\`(.*?)\`!', $page->text()->raw(), $matches);

  $list = [];
  if ($matches[1] > 0) {
    foreach($matches[1] as $match) {
      $list[] = $match;
    };
  }

  return $list;

};

in the adapted page-method for the structured i took out ->text()->raw() since $tx->text() in the template it’s already printing the raw text version (eg the markdown).

i think though it’s not working because i’m using the $page object and with a structured field it’s different?

i realised i can just move the code in page-method inside the template / snippet since it’s a one-off thing and i probably will avoid the page-method limitation problem :slight_smile: