I am trying to display every Item from my Database to the Admin panel where i want to apply changes, etc. For now i use test products in my models.php file. I already followed the “Virtual files” tutorial, but i am stuck on that point to display it on the Panel. I can already display everything in my template, but not in my Panel.
I have created a Folder /site/plugins/virtual-products/…
/index.php
use Kirby\Cms\App as Kirby;
require __DIR__ . '/models/product.php';
Kirby::plugin('products/virtual-product', [
'blueprints' => [
'files/virtual-product' => __DIR__ . '/blueprints/files/virtual-product.yml',
'pages/product' => __DIR__ . '/blueprints/pages/product.yml',
],
'pageModels' => [
'product' => 'ProductPage',
],
'templates' => [
'product' => __DIR__ . '/templates/product.php',
],
]);
/blueprints/pages/product.yml
title: Produkt
fields:
sku:
label: SKU
type: text
required: true
name:
label: Name
type: text
required: true
price:
label: Price (in cents)
type: number
required: true
vat_rate:
label: VAT Rate (%)
type: number
required: true
quantity:
label: Quantity
type: number
required: true
image:
label: Image URL
type: text
in_stock:
label: In Stock
type: toggle
isdiscounted:
label: Discounted?
type: toggle
is_highlight:
label: Highlighted?
type: toggle
/models/product.php (for test data, without database)
use Kirby\Cms\Page;
class ProductPage extends Page {
public function display() {
if ($this->files !== null) {
return $this->files;
}
$files = [
'sku' => '123',
'name' => 'Test',
'price' => '100',
'vat_rate' => '7',
'quantity' => '5',
'image' => '/media',
'in_stock' => true,
'isdiscounted' => false,
'is_highlight' => true,
];
return $files;
}
}
/site/blueprints/pages/home.yml
sections:
products:
type: pages
template: product
layout: cards
size: medium
headline: Meine Produkte