Snippetfield blank page


#1

Hi
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 :

  plats:
    label: Plats
    type: snippetfield
    snippet: mydir/snippet
    style: items
    fields:
      plat:
        label: Plat
        type: text
        icon: cutlery
      detail:
        label: Détail
        type: textarea
      prix:
        label: Prix
        type: text
        icon: eur
        width: 1/2
      gluten:
        label: Gluten 
        type: switch
        texts:
          - 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) ?>
  </div>
  <?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>

    <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') ?>
    </a>
  </nav>
  <?php endif ?>
</div>          
<?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.


#2

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.


#3

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">
   <tr>     
        <th>
           <?= $values->plat() ?>
        </th>
        <th>
            <?php echo excerpt($values->detail(), 30) ?>      
        </th>
        <th>
           <?= $values->prix() ?> €
        </th>
        <th>
           <?= $values->gluten() ?>          
        </th>  
        <th class="last">
            <a data-modal class="btn" href="<?php __($field->url($entry->id() . '/update')) ?>">
                <?php i('pencil') ?>
            </a>
        </th>
        <th class="last">
            <a data-modal class="btn" href="<?php __($field->url($entry->id() . '/delete')) ?>">
                <?php i('trash-o') ?>
            </a>
        </th>
    </tr>
</table>
<?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’


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

#5

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.


#6

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'; ?>

#7

Yes perfect !!! Thank you very much