We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Question

Table template

Is it possible to create a template that allows editors to build a table on the fly?

I have tried using blocks to achieve it but can't get my head around whether it is possible or not.

Here is my code for the template but the blocks don't show up in the editor.

<h3><perch:content id="heading" type="text" label="Heading" title="table title if required"></h3>
<perch:before><div class="table--responsive">
        <table class="table--stripes">
            </perch:before>

            <perch:blocks>
                <perch:block id="table-header-section" title="Header row(s) of table">
                        <thead>
                            <tr>    
                                            <th><perch:content id="headertext" type="text" label="Text" html editor="ckeditor" required title="table header cell text"></th>
                            </tr>
                        </thead>
            </perch:block>
                    <perch:block id="table-body-section" title="Body row(s) of table">
                            <tbody>
                                <tr>    
                                                <td>
                                                <perch:content id="bodytext" type="text" label="Text" required title="table header cell text">
                                        </td>
                                </tr>
                            </tbody>
                        </perch:block>
            </perch:blocks>

<perch:after>
    </table>
</div>
</perch:after>

And even if they did show up in the editor, they would only allow me to put in one header cell and one data cell per table.

Andrew Auld

Andrew Auld 0 points

  • 1 year ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you know the number or columns you can use a repeater to enable the editor to add rows.

If you need to create any arbitrary table, you may need to nest repeaters inside blocks, but that sounds a bit messy.

Yes, I wondered about repeaters. But I need to get my head around how they work. Back to the docs!

I'll give it a go but might end up giving up and just letting editors create their own tables in the ckeditor.

This is not a bad solution; https://github.com/siansell/perch-cms-fieldtype-table

Haven't tried it extensively, but from my little testing, it seemed to do the job quite well.