Display products from pgsql Database in Admin Panel via Plugin

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

It sounds a lot like you would be better of with representing your products as virtual pages - it’s a bit easier than directly jumping to virtual files. Have a look at https://getkirby.com/docs/guide/virtual-content/simple-virtual-page

Your `display` method isn’t used anywhere - not sure where you picked that up.

Maybe the key here is that the first thing you need is not a page model for your product page but rather for the patron - so e.g. the products page. This parent page in its `::children()` then takes the data for your products and creates virtual pages for each and returns these as its children. Hope this gets you off in the right direction :slight_smile: