In a custom panel Field it was possible to use it’s own api routes for example to send an email. How do you do this in a custom panel section. And is it also possible to get the content of the variables of the current page?
index.php
<?php
Kirby::plugin('custom/modified', [
'sections' => [
'modified' => [
'props' => [
'headline' => function (string $headline) {
return $headline;
},
],
'computed' => [
'text' => function () {
return 'The page has been modified at ' . $this->model()->modified('d.m.Y H:i:s');
}
],
'api' => function() {
return [
[
'pattern' => 'send-email',
'method' => 'POST',
'action' => function () {
$address = $this->field()->model()->emailfield()->value();
return ['status' => 'success'];
}
]
];
},
]
]
]);
index.js
panel.plugin('custom/modified', {
sections: {
modified: {
data: function () {
return {
headline: null,
text: null
}
},
created: function() {
this.load().then(response => {
this.headline = response.headline;
this.text = response.text;
this.endpoints = Object;
});
},
methods:{
sendEmail() {
this.$api.post(this.endpoints.field + '/send-email')
.then(function(response) {
// do something
console.log("succes");
})
.catch(function(error) {
// do something
console.log('error');
});
}
},
template: `
<section class="k-modified-section">
<button class="email-button" @click="sendEmail">Sent mail</button>
<k-headline>{{ headline }}</k-headline>
<k-text>{{ text }}</k-text>
</section>
`
}
}
});