Giter Club home page Giter Club logo

Comments (4)

distantnative avatar distantnative commented on May 23, 2024

@MikeHarrison could you please share the code for the virtual pages in here as well? So probably the artwork and images models

from kirby.

MikeHarrison avatar MikeHarrison commented on May 23, 2024

Hi,

Sure no problem, they are below:

site/models/artwork.php

<?php
class ArtworkPage extends Page
{
  public function children(): Kirby\Cms\Pages
  {
    $images = [];
    
    
    if($image = $this->mainImage()->toFile()):
      $images[] = [
        'slug'     => $image->name(),
        'num'      => 0,
        'template' => 'lightbox-image',
        'model'    => 'lightbox-image',
      ];
    endif;
    

    if($this->additionalImages()->isNotEmpty()):
      foreach ($this->additionalImages()->toFiles() as $image) {
        $images[] = [
          'slug'     => $image->name(),
          'num'      => $image->sort()->value(),
          'template' => 'lightbox-image',
          'model'    => 'lightbox-image',
        ];
      }
    endif;

    return Pages::factory($images, $this);
  }
}

site/models/lightbox-image.php

<?php

class LightboxImagePage extends Page
{
  public function image(string $filename = null): Kirby\Cms\File|null
  {
    if (!$filename) {
      return $this->parent()->images()->template('image')->findBy('name', $this->slug());
    }

    return parent::image($filename);
  }
}

I do also have a minimal example set up in the Plainkit if that is of use, I can send a zip file over

from kirby.

MikeHarrison avatar MikeHarrison commented on May 23, 2024

Hi!

Is there anything else I can do to help with getting this diagnosed or addressed? I am keen to find a resolution if possible - is it a bug, or an error in my implementation?

from kirby.

MikeHarrison avatar MikeHarrison commented on May 23, 2024

I have got this working now, with help from @texnixe . Updated model is below for reference, I will close the issue as it was my implementation not a Kirby problem.

<?php
class ArtworkPage extends Page
{
    public Pages|null $children = null;

    public function children(): Kirby\Cms\Pages
    {

        if ($this->children instanceof Pages) {
            return $this->children;
        }

        $images = [];


        if($image = $this->mainImage()->toFile()):
          $images[] = [
            'slug'     => $image->name(),
            'num'      => 0,
            'template' => 'lightbox-image',
            'model'    => 'lightbox-image',
          ];
        endif;
        
    
        if($this->additionalImages()->isNotEmpty()):
          foreach ($this->additionalImages()->toFiles() as $image) {
            $images[] = [
              'slug'     => $image->name(),
              'num'      => $image->sort()->value(),
              'template' => 'lightbox-image',
              'model'    => 'lightbox-image',
            ];
          }
        endif;

        return $this->children = Pages::factory($images, $this);
    }

}

from kirby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.