How to access current $page->title() in custom block?

Hi,
I´m trying to create a pagetitle-block, which »only« outputs the pagetitle of the current page.

I´ve tried to get the current page object directly in vue:
this.$api.site.page.title

Or passing the current page with a custom route:

'routes' => function($kirby) {
  return   [
   [
     'pattern' => 'myplugin/pagetitle',
     'action'  => function () use ($kirby) {
        return $kirby->site()->page()->title();
      }
   ]
]

Without success.

What would be the correct way to do it?

Cheers
Peter

I think something like this in Vue:

this.$store.getters["content/values"]()["title"]
2 Likes

Wow, thank you jimbobrjames!

This works.

Is there some secret documentation about this.$black.magic() kirby-vue-api, or did you get that by absorbing the source?

Would love to understand it, but can´t find the entrance.

1 Like

The kirby team gave me that line a couple of years ago. Im not sure if its in the docs. I believe @distantnative pointed me in the right direction at the time. He might be able to give some insight here.

Whoa… A place to find all these cryptic hidden commands would be reallllyyyyy helpful…

1 Like

// PAGE CONTENT

// Get the a page-field
this.$store.getters["content/values"]()['pagetitle'])

// Update a page-field
this.$store.dispatch("content/update", ["pagetitle", "GREAT SCOTT, now delete me!"])

// BLOCK CONTENT

// Get a block-field
this.content.height_value_em

// Update a block-field
this.$emit('update', {height_value_em: 1})