Hide repeat group table if empty

Hi,
When there is no repeat group, the table <head> still shows up in the detail view... how would you hide it in a custom detail template ?
Is there any function I can use ?
For the time being, I have to query the db (the repeat group db table) to count rows... but queries in the template files, you know...

Thanks for any help !
 
You'd need to clone the 'bootstrap' details template, edit default_repeatgroup_table.php, and wrap it up in a test like ...

Code:
$group = $this->group;
// only output if there the group is not empty
if (count($group->subgroups) > 0) :
?>
<table class="table table-striped repeatGroupTable">
    <thead>
        <tr>
    <?php
    // Add in the table heading
    $firstGroup = $group->subgroups[0];
    foreach ($firstGroup as $el) :
        $style = $el->hidden ? 'style="display:none"' : '';
        ?>
        <th <?php echo $style; ?> class="<?php echo $el->containerClass?>">
            <?php echo $el->label_raw?>
        </th>
        <?php
    endforeach;

    // This column will contain the add/delete buttons
    if ($group->editable) : ?>
    <th></th>
    <?php
    endif;
    ?>
    </tr>
    </thead>
    <tbody>
        <?php

        if (!$group->newGroup) :
            // Load each repeated group in a <tr>
            $this->i = 0;
            foreach ($group->subgroups as $subgroup) :
                $this->elements = $subgroup;
                echo $this->loadTemplate('repeatgroup_row');
                $this->i ++;
            endforeach;
        endif;
        ?>
    </tbody>
</table>
<?php
endif;
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top