Virtual Page doesnt display image

,

Hey, I’m trying to create virtual products and configure them in the panel. I’ve already managed to display everything from the PostgreSQL database, but I can’t get the image to show, and I don’t know why. I was inspired by the Virtual Page Guide. :slight_smile: Here’s the code:

index.php

<?php

use Kirby\Cms\App as Kirby;

require __DIR__ . '/models/products.php';

Kirby::plugin('kdx/virtual-products', [
  'blueprints' => [
    'files/virtual-file'  => __DIR__ . '/blueprints/files/virtual-file.yml',
    'pages/product'        => __DIR__ . '/blueprints/pages/product.yml',
    'pages/products'        => __DIR__ . '/blueprints/pages/products.yml',
  ],
  'pageModels' => [
    'products'              => 'ProductsPage',
  ],
  'templates'  => [
    'product'              => __DIR__ . '/templates/product.php',
  ],
]);

modes/products.php

<?php
use Kirby\Cms\Page;
use Kirby\Cms\Pages;
use Kirby\Cms\File;

class ProductsPage extends Page
{
    public function children(): Pages
    {
        $products = [];
        $pdo = Database::getInstance()->getPDO();

        $stmt = $pdo->query("SELECT * FROM products");
        foreach ($stmt as $row) {
            $products[] = new Page([
                'slug'     => $row['sku'],
                'template' => 'product',
                'model'    => 'products',
                'content'  => [
                    'title'        => $row['name'],
                    'price'        => $row['price'],
                    'vat_rate'     => $row['vat_rate'],
                    'quantity'     => $row['quantity'],
                    'image'        => $row['image'],
                    'in_stock'     => $row['in_stock'] ? 'true' : 'false',
                    'isdiscounted' => $row['isdiscounted'] ? 'true' : 'false',
                    'is_highlight' => $row['is_highlight'] ? 'true' : 'false',
                ],
                'parent' => $this,
            ]);
        }

        return new Pages($products);
    }

}

blueprints/pages/product.yml

title: Product
icon: 🛒

options:
  create: false
  delete: false
  update: false

fields:
  title:
    label: Name
    type: text


  price:
    label: Price (€)
    type: number


  vat_rate:
    label: VAT Rate (%)
    type: number


  quantity:
    label: Quantity
    type: number


  in_stock:
    label: In Stock
    type: toggle


  isdiscounted:
    label: Discounted
    type: toggle


  is_highlight:
    label: Highlighted
    type: toggle


  image:
    label: Produktbild
    type: files
    layout: cards
    max: 1
    required: true


blueprints/pages/products.yml

title: Produkte

sections:
  files:
    type: pages
    label: Produkte 
    layout: cards
    size: medium
    image:
      cover: true

A files field expects an array of file UUIDS or file Ids. Impossible to tell what

$row[‘image’] contains, probably the url to a file? Where does this file live?

Thanks for the fast reply! :slight_smile:

The image is a string reference to the image, example: /media/products/apple.jpg, /media/products/banana.jpg

It won’t work that way. As I said, the field either needs a uuid or id to a file inside the /content folder.