mrtn
August 13, 2023, 2:05pm
1
I have a simple plugin index.js
:
panel.plugin("me/mycustomblock", {
blocks: {
mycustomblock: {
template: `
<p>
{{ content.headline }}
</p>
`
}
}
});
This part works — thanks to content
I have access to the fields and can preview them. But I also want to access some global data on site
level.
{{ site.author }}
does not work:
Can’t find variable: site
How can I access fields in a plugin template on the site
level?
You have to make a call to the API, I don’t think the site object is accessible in this context out of the box.
1 Like
mrtn
August 21, 2023, 10:49am
3
Do you have an example of what such an API call would look like in a template?
I did found $api->call() but I’m not sure what the $path
parameter refers to in this context. (is PHP even allowed within template
?)
You can find an example api call here: Block factory: Creating your own blocks collection | Kirby CMS
And no, you cannot use PHP in a JavaScript file.
mrtn
August 31, 2023, 7:04am
5
I’ve read all links provided – unfortunately, I’m still not able to figure out how to access data from site
within my blocks index.js
I get that I have to access the data in a custom method placed in computed
. However all examples provided just call contents from this
. Here’s what I’ve tried:
panel.plugin("me/mycustomblock", {
blocks: {
mycustomblock: {
computed: {
siteTitle() {
return this.page.site.title;
},
},
template: `
<p>
<b>Title: {{ siteTitle }}</b></br>
</p>
`
}
}
});
This didn’t work — although the documentation (for my understanding) says the page object should have a site object available.
undefined is not an object (evaluating ‘this.page.site’)
Any help would be much appreciated.