Blocks are not showing up

Hey I got problem with the blocks function.

I have used blocks before, and it is super wired that they are not working this time. So I am hoping that someone could point me in a direction for my troubleshooting. :face_with_spiral_eyes:

Here is what works:

  • panel – custom blocks are visible
  • blueprints – for the custom blocks are connected

What doesn’t work:

  • calling the blocks with the toBlocks() method in the template.

What I have tried so far:

  • checking for any misspelling
  • using the toBlocks() method in another scope
  • Reducing the complexity of the block snippet (that does not seems to be the problem)
  • renaming the field with the type: blocks in the page yml
  • compared (a lot) with other projects where it works
  • checking the kirby version: 3.6.0

The thing is, that is no fancy approach in the case. The template seems simply to not get the blocks I set up in the panel:
Bildschirmfoto 2022-06-30 um 16.30.59
I this embla__container should be the block.

Template: templates/project.php

<?php snippet('header') ?>
<?php snippet('topLine2') ?>
<div class="grid_wrapper">

   <div class="embla slider img_slider">
      <div class="embla__container">
         <?= $page->content()->toBlocks(); ?>
      </div>
   </div>
</div>

<?php snippet('bottomLine2') ?>
<?php snippet('footer') ?>

Page blueprint: blueprints/pages/project.yml

title: project
icon: 🖼
columns:
 - width: 1/1
   sections:
      imageslider:
         type: fields
         fields:
            content:
                 type: blocks
                 fieldsets:
                 - datei
                 - reihe
  - width: 1/2
     sections:
          generell:
               type: fields
               fields:
                  meta:
                      type: textarea
                      buttons: false
                   cover:
                      type: radio
                      options: query
                      query: page.files

Block Snippet: snippets/blocks/datei.php

<figure class="embla__slide image_Column slide-<?= $block->indexOf() ?> <?= $block->image()->toFile()->orientation() ?>">
    <img class="img_Container <?= $block->image()->toFile()->orientation() ?>" src="<?= $block->image()->toFile()->url() ?>" alt="<?= $block->image()->toFile()->alt() ?>">
</figure>

Block blueprint: blueprints/blocks/datei.yml

name: Bild/Video
icon: image
preview: image
fields:
   art:
      label: Art
      type: radio
      columns: 2
      default: "bild"
      options:
         bild: Bild
         video: Video
   image:
      label: field.blocks.image.name
      type: files
      query: page.images
      multiple: false
      layout: cards
      size: huge
      image: 
         back: black
      uploads:
         template: project_Image
      when:                        
         art: bild
    video:
       label: Videolink
       type: text
       when:
         art: video
     title:
       type: text
     text:
       type: textarea

For me it looks like in the textbook. :smiley:

The field shouldn’t be called content, or you would have to get the field with $page->content()->get('content'), because content() is a page method.

I see. I tried this before – renaming the field… But it does not solve the problem here:

<?= $page->inhalt()->toBlocks(); ?>

blueprint:

   fields:
      inhalt:
        type: blocks
        fieldsets:
          - datei
          - reihe

or is there also a page method called inhalt()? :innocent:

Nope, we definitely do not use German method names… so you’re absolutely safe with those.

But to get back to the original problem:

Are those blocks actually saved in your content files?

There are some issues in your snippets, like missing checks for file objects that will result in an error if the files don’t exist, but not sure if that’s the problem here.

Your code should look like this:

<?php if ($image = $block->image()->toFile()): ?>
  <figure class="embla__slide image_Column slide-<?= $block->indexOf() ?> <?= $image->orientation() ?>">
    <img class="img_Container <?= $image->orientation() ?>" src="<?= $image->url() ?>" alt="<?= $image->alt() ?>">
  </figure>
<?php endif ?>

Sry. Looks like the content() named file was the solution…
I just started the localhost setup again, and erased all the browser data… now it works.

I don’t have a clue, because I changed the names before, twice…
-.-

Sry. For bothering you that late hour.
Thanks for the tip, with the toFile() check.