Structure field empty cols


Is there a kirby-helper to know if a column of the structur fields has not been filled.


greetings perry.

I think it actually sees things as rows not columns, but either way im not aware of any helper to check that. You could use isEmpty() or set validation on the fields them selves so they have to be filled in.

alternatively you could extend the built in field to have that functionality (aka a custom field plugin).

Another way is to get clever with the loop in the template - it shouldnt be too hard to check if all of the last entries are empty before working with it. It’s an array after all.

Whats your use case? what does it mean for the front end if that column is empty?

Whats your use case?

If I loope through a structur field, it would be cleaner if the last column were empty they would not create.
There are probably different techniques to remove the empty column. The simplest would probably be with css: empty {} hide the empty column, it would be cleaner on the severside

I thought you wanted to hide empty columns in the Panel. If it is a matter of not displaying completely empty columns on the frontend, you can do it like this (don’t know if this is the best way to go about it, but will do the job):

// fetch all relevant fields into an array
$fields = ['col1', 'col2', 'col3'];
$items = $site->tablefield()->toStructure();

// loop through fields  and unset the field from the fields array
// if the resulting array from the pluck method is empty
foreach ($fields as $key => $field) {
  if (empty($items->pluck($field, ','))) {

// then use only those fields to build your table
$html = '<table class="kirbytag-table">';
foreach($items as $row)  {
    $html .= '<tr>';
    foreach ($fields as $field) {
        $html .= '<td>';
        $html .= $table->{$field}()->html();
        $html .= '<td>';
    $html .= '</tr>';	

$html .= '</table>';		


thank you @texnixe.