Fabrik Custom template Help

Hope someone with more experience than me can help this amateur.

I am trying to create a custom template.

I have a form with several tabs on it.

On one of these tabs there are 24 elements.

For the 5th,10th,15th and 20th element I want to change the table heading to span 4 elements. Then I can hide the others in CSS.

If I change this in a copied default_repeat_group_table.php

Code:
// 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;

To this

Code:
// Add in the table heading
    $firstGroup = $group->subgroups[0];
    foreach ($firstGroup as $el) :
        $style = $el->hidden ? 'style="display:none"' : '';
        ?>
        <th colspan= "4" <?php echo $style; ?> class="<?php echo $el->containerClass?>">
            <?php echo $el->label_raw?>
        </th>
        <?php
    endforeach;

It changes all my headings to span 4 as you would expect.

I assume that I need to test for the group and then test for the element with IF , but if I'm honest I don't really have a great grasp of PHP.
I could write an IF to select a variable of 4 or 1 depending on element and group, but I don't understand how to use that result?

I referred to this

Thank you Rob great video.
 
This is how I achieved this, it may not be the most elegant approach!

In a copy of default_repeatgroup_table.php I replaced this

Code:
    // 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;

with this

Code:
// Add in the table heading
    $firstGroup = $group->subgroups[0];
    //Create an array of the elements that the heading will require a wider heading
    $fourSpanElements = array(
                              "tbl_inspections_95_repeat___tp_0_0"
                              ;


    //Create an array of elements that the heading will need to be not displayed so that the table displays correctly
    $standardElements = array(
                              "tbl_inspections_95_repeat___tp_1_0",
                              "tbl_inspections_95_repeat___tp_2_0",
                              "tbl_inspections_95_repeat___tp_3_0"
                              );


    foreach ($firstGroup as $el) :
        $style = $el->hidden ? 'style="display:none"' : '';
        //make the title span 4 elements and centralise the text  
        if (in_array($el->id, $fourSpanElements)) {
           $span = "colspan = 4;";
           $align = 'style="text-align:center;"';
        //hide the labels
        }elseif(in_array($el->id, $standardElements)){
           $style ='style="display:none"';
        }
        ?>

        <th <?php echo $style; ?> <?php echo $align; ?> <?php echo $span;?>class="<?php echo $el->containerClass?>">
            <?php echo $el->label_raw?>
        </th>
        <?php
    endforeach;

The result is that the heading for 'tbl_inspections_95_repeat___tp_0_0' covers four elements in total and is centered on them.
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top