Snippetfield blank page

I’m trying to install the snippetfield plugin but I’m getting a blank page in the panel with the default config.
I’m running with 2.5.6, and this is my blueprint :

    label: Plats
    type: snippetfield
    snippet: mydir/snippet
    style: items
        label: Plat
        type: text
        icon: cutlery
        label: Détail
        type: textarea
        label: Prix
        type: text
        icon: eur
        width: 1/2
        label: Gluten 
        type: switch
          - Avec
          - Sans
        icon: bell
        width: 1/2

The snippet I’m using is the same as the default here

<?php foreach($field->entries() as $entry): ?>
<div class="structure-entry" id="structure-entry-<?php echo $entry->id() ?>">
  <div class="structure-entry-content text">
    <?php echo $field->entry($entry) ?>
  <?php if(!$field->readonly()): ?>
  <nav class="structure-entry-options cf">
    <a data-modal class="btn btn-with-icon structure-edit-button" href="<?php __($field->url($entry->id() . '/update')) ?>">
      <?php i('pencil', 'left') . _l('fields.structure.edit') ?>

    <a data-modal class="btn btn-with-icon structure-delete-button" href="<?php __($field->url($entry->id() . '/delete')) ?>">
      <?php i('trash-o', 'left') . _l('fields.structure.delete') ?>
  <?php endif ?>
<?php endforeach ?>

I tried multiple times to remove certain plugins, and I did a very basic file of the snippet.php but I don’t understand most of it…I have set c::set('debug', true); but I still have a blank page. Do you have some advices ?

EDIT : I could target the bug and this appear to come from <?php echo $field->entry($entry) ?>. Every time I write it, I get a blank page.

This snippet you mention above is not supposed to be used as a snippet for the entries, it is part of the plugin. You can access field values via the $valuesvariable. A simple example for your field would be:

<?= $values->plat() ?>
<?= $values->detail() ?>

Check out the snippetfield documentation.

Thank you texnixe, I was totally out of the box ! I did’nt find any snippet example, so I was wrong. I created a snippet close to the result I was looking for, and I’m very happy. The list is for a menu restaurant, and the user can modify, remove each lines of it menu.

<?php foreach($field->entries()->limit(1) as $entry): ?>
<table class="structure-table">
           <?= $values->plat() ?>
            <?php echo excerpt($values->detail(), 30) ?>      
           <?= $values->prix() ?> €
           <?= $values->gluten() ?>          
        <th class="last">
            <a data-modal class="btn" href="<?php __($field->url($entry->id() . '/update')) ?>">
                <?php i('pencil') ?>
        <th class="last">
            <a data-modal class="btn" href="<?php __($field->url($entry->id() . '/delete')) ?>">
                <?php i('trash-o') ?>
<?php endforeach ?>

Thank you very much ! My next question is : how to replace the true/false attribute from a checkbox displayed in a blueprint by something else : a translation or ‘oui/non’

<?= $values->checkbox()->bool()? 'Oui': 'Non'; ?>

Cool ! But it goes an error message : Method SnippetfieldField::__toString() must not throw an exception.
I just did <?= $values->gluten()->bool()? 'Oui': 'Non'; ?> because gluten is a checkbox with switchfield plugin I posted testerday.

But what does the switch field store in the content file? Maybe not a boolean value?

Edit: It saves a string, so you have to modify the code:

<?= $values->gluten() == 'true'? 'Oui': 'Non'; ?>
1 Like

Yes perfect !!! Thank you very much