Snippet not working on domain

I have an issue where Kirby is ignoring the code in a snippet on my live domain, but the code works on a local Vagrant server. Live domain is running CentOs 7 and my Vagrant box runs Ubuntu 16. Both servers are using PHP 7.

I don’t believe the issue to file permissions related, I have checked these.

Anyone had an issue like this? Kirby debugging is on and i am not getting an error.

I’m using kirby builder and other builder snippets work fine on both servers. The snippet that does not work contains this:

<?php if($page->template() == 'work' OR $page->template() == 'home'): ?>

  <?php if ($data->picture()->isNotEmpty()): ?>
    <?php if($data->toggle() == 'true'): ?>
      <section class="single-image">
        <?php $image = $data->picture()->toFile();?>
        <img src="<?php if($image) echo $image->url();?>" style="max-width:<?= $image->width() ?>px" alt="<?php if($image) echo $image->alt();?>">
    <?php endif ?>
  <?php endif ?>

<?php else: ?>

  <?php if ($data->picture()->isNotEmpty()): ?>
      <section class="single-image">
        <?php $image = $data->picture()->toFile();?>
        <img src="<?php if($image) echo $image->url();?>" style="max-width:<?= $image->width() ?>px" alt="<?php if($image) echo $image->alt();?>">
      </section>
  <?php endif ?>

<?php endif ?>

First of all, I would test if the snippet is loaded at all, for example by placing some simple code right at the top (comment all the rest for testing):

<?php echo "hello, I'm your missing snippet"; ?>

By the way, it would be absolutely sufficient just to check for image (because if the picture field is empty, $image would return false anyway):

<?php if($page->template() == 'work' OR $page->template() == 'home'): ?>

    <?php if($data->toggle() == 'true'): ?> 
    <?php $image = $data->picture()->toFile(); ?>
    <?php if($image): ?>
      <section class="single-image"> 
        <img src="<?p= $image->url();?>" style="max-width:<?= $image->width() ?>px" alt="<?= $image->alt();?>">
      </section>
    <?php endif ?>

<?php else: ?>

      <?php $image = $data->picture()->toFile(); ?>
      <?php if($image): ?>
        <section class="single-image">
          <img src="<?= $image->url();?>" style="max-width:<?= $image->width() ?>px" alt="<?= $image->alt();?>">
        </section>
    <?php endif ?>

<?php endif ?>

Thanks… i actually already put an H1 tag outside of the IF statement on the very first line and that didnt work, It is simply ignore either the file or the entire file contents. I have tried renaming the snippet… ive checked case sensitivity on the yaml and a whole bunch of stuff. Kirby Builder simply refuses to show the code from that snippet when i run it on Centos7. I have tried two seperate centos servers and neither of them work. Only runs on Ubuntu.

Even with just an H1 tag in the snippet, it still fails to display.

Have you tried to load the snippet explicitly (outside of the foreach loop)?

<?php snippet('path_to_snippet') ?> 

And the name of the snippet is 100% correct like defined in the blueprint (maybe the Ubuntu server loads stuff from cache)?

Names are correct. Calling the snippet directly does not work either. Cache is disabled in Kirby config.

The strange thing is, the snippet works inside the Builder panel in the kirby edit panel for the page… its is displaying the image in the preview panel. It just doesn’t work on the actual site. It is really odd!

That’ s really weird. Have you tried to recreate the file?

Yes. I even logged on to the sever and recreated them directly on the server… still nothing.

Hm, I’m running out of ideas. Guess there’s some little snippet eater under way on the server :wink:

Have you tried with a CentOS Vagrant box?

I’m just trying that now.

Other things to try out:

  • Make sure Kirby versions are the same
  • Make sure the content is the same
  • Make sure all the files are the same on server and localhost
  • Make sure you don’t use <? anywhere
  • Make sure the snippet is not overwritten with another snippet with the same name (could happen when you use registry set)
  • Make sure you don’t use a cache

Im am really running out of options. I havent been able to get a CentOS vagrant box setup, there are no centos boxes preconfigured as a PHP / Apache server that i can find and i have wasted 3 hours trying set one up from scratch.

It works on my Ubuntu vagrant which is running on Scotchbox 3 (licensed pro version). Is there anything in its specification that would cause an issue if it was missing on CentOS?

How is it possible that the snippet works fine within Kirbies panel but does not work on the actual webpage? That seems really crazy. The rest of the page works, but for some reason it skips over the 4 lines of code in that snippet and moves on to the rest of the code.

Here is the whole page template that calls the snippet:

<!DOCTYPE html>
<html lang="en">
<head>
  <?php snippet('site-htmlhead') ?>
  <?php snippet('site-css', ['livedomain' => c::get('livedomain')]) ?>
</head>

  <?php snippet('site-sectionhook') ?>
  <?php snippet('site-menu') ?>



    <main id="middle">

      <section class="work-list">

        <?php foreach($site->find('work')->children()->paginate(2) as $workpost): ?>

                  <article class="work-item">

                  <header class="title">
                    <h1><a href="<?= $workpost->url() ?>"><?= $workpost->title()->html() ?></a></h1>

                  </header>

                  <?php if($workpost->client()->isNotEmpty()): ?>
                  <div class="block-1">
                    <div class="block-col client">
                      <?php if($workpost->clienturl()->isNotEmpty()): ?>
                        <p><strong>Client:</strong> <a target="_blank" href="<?= $workpost->clienturl()->html() ?>"><?= $workpost->client()->html() ?></a></p>
                        <?php else: ?>
                        <p><strong>Client:</strong> <?= $workpost->client()->html() ?></p>
                      <?php endif ?>
                    </div>
                  </div>
                  <?php endif ?>

                  <?php if($workpost->template() == 'workpost'): ?>

                  <?php foreach($workpost->builder()->toStructure() as $section): ?>
                    <?php snippet('builder/' . $section->_fieldset(), array('data' => $section)) ?>
                  <?php endforeach ?>

                  <?php else: ?>

                    <div class="text-extract">
                    <?= excerpt($workpost->text(), 300) ?>
                    </div>




                <?php endif ?>

                <a class="btn" href="<?= $workpost->url() ?>">Read More</a>

                </article>



      <?php endforeach ?>



      </section>

      <?php snippet('site-pager') ?>

    </main>


  <?php snippet('site-footer') ?>
  <?php snippet('site-js', ['livedomain' => c::get('livedomain')]) ?>
</body>
</html>

And the blueprint:

title: Work Post
pages: false
files: true
  fields:
    alt:
      label: Alt Text
      type: textarea

fields:
  seotitlemeta:
    label: Basic Title & SEO information
    type: headline
  title:
    label: Title
    type: text
    help: The title that will show on the webpage
    icon: font
    width: 1/3
  seotitle:
    label: SEO Title
    type: text
    help: This will be used in the page code for SEO purposes
    icon: font
    width: 1/3
  seometa:
    label: SEO Meta
    type: text
    help: This will be used in the page code for SEO purposes
    icon: font
    width: 1/3
  seokeywords:
    label: SEO Keywords
    type: tags
    help: Keyword for SEO
    icon: font
    width: 1/3
  client:
    label: Client Name
    type: text
    help: Who was the client?
    icon: font
    width: 1/3
  clienturl:
    label: Client Website
    type: url
    help: Who was the client?
    width: 1/3
  workdesc:
    label: Work Description
    type: textarea
    help: A description of what the work involved
  builder:
    label: Show and Tell
    type: builder
    fieldsets:
      singleImage:
        label: Single Image
        snippet: builder/singleimage
        fields:
          picture:
            label: Image
            type: image
          toggle:
            label: Is this a featured work?
            type: toggle
            text: yes/no
            width: 1/3
      slideshow:
        label: Slideshow
        snippet: builder/slideshow
        fields:
          slide:
            label: Slides
            type: gallery
          toggle:
            label: Is this a featured work?
            type: toggle
            text: yes/no
            width: 1/3
      video:
        label: Video
        snippet: builder/video
        fields:
          vid:
            label: Video URL (Vimeo or Youtube)
            type: text
          toggle:
            label: Is this a featured work?
            type: toggle
            text: yes/no
            width: 1/3
      sketchfab:
        label: Sketchfab
        snippet: builder/sketchfab
        fields:
          sfembed:
            label: Embed a Sketchfab Widget. Just enter the number on the end of the Sketchfab URL.
            type: text
          toggle:
            label: Is this a featured work?
            type: toggle
            text: yes/no
            width: 1/3

And the content file:

Seotitlemeta:

----

Title: Folio Image

----

Seotitle: Folio Image

----

Seometa: Folio Image

----

Seokeywords: Animation

----

Client:

----

Clienturl:

----

Workdesc: dfgdfgdfg

----

Builder:

-
  picture: qz_ylhssaik.jpg
  toggle: 'true'
  _fieldset: singleImage
-
  slide: |
    - kioskvfx-rt_23.jpg
    - kioskvfx_german_modern_building_05.jpg
    - qz_ylhssaik.jpg
  toggle: 'true'
  _fieldset: slideshow

All the other fields and snippets work… just the picture field does not work on the live CentOS server.

Maybe something with the camelcase of the fieldset?
I’m not completely sure but you reference to the snippet in the blueprint with builder\singleimage but the fieldset is saved as singleImage. Therefore the loop would theoeratically try to call builder\singleImage.

1 Like

Im sure i checked case sensitivity 2 days ago (it’s been emotional!) but i will give it another go…

In general, you should always stick with lower case letters in filenames.

OMG!!! I cant beleive it it. I renamed the snippet file to singleImage.php and it works!

Your my new best friend. :slight_smile:

Yes, but please, please don’t use camelCase in filenames!

1 Like

Glad I could help.

But as @texnixe mentioned I would stick to lowercase for filenames. So just put a simple strtolowerto your snippet call.

1 Like