Skip to content

Tables: Hidden Templates & Repeats ​

When every row of a list looks the same, there's no need to send the whole HTML back with render.fragment each time. Instead:

  1. Put one hidden template row on the page (data-linker-ref-dom).
  2. The Linker method returns the built-in dom.repeat action with data only.
  3. The browser copies the template, fills in the %field% placeholders, and inserts the rows into the table.

Full example: a budget list ​

Template ​

blade
<div @linker('budget')>                                    {{-- every hook must be inside the mount point --}}
    <p><span data-linker-ref-meta="budget:total">0</span> rows,
       page <span data-linker-ref-meta="budget:current_page">1</span></p>

    <table>
        <thead>
            <tr><th>Year</th><th>Month</th><th>Amount</th><th></th></tr>
        </thead>
        <tbody>
            {{-- 1. Hidden template: not shown, not bound --}}
            <tr class="hidden" data-linker-ref-dom="budget">
                <td>%year%</td>
                <td title="%lang:budget.row%">%month%</td>
                <td class="amount">%amount%</td>
                <td>
                    <button data-linker-call="delete"
                            data-linker-args='{"id": %id%}'
                            data-linker-confirm="Delete this row?"
                            data-linker-confirm-danger>Delete</button>
                </td>
            </tr>

            {{-- 2. Empty state (optional). Hide it on the server when there is data, to avoid a flash --}}
            <tr data-linker-ref-empty="budget" @class(['hidden' => ($budgetSeed['total'] ?? 0) > 0])>
                <td colspan="4">No data</td>
            </tr>
        </tbody>
    </table>

    <button data-linker-call="show" data-linker-args='{"page": 2}'>Next page</button>

    {{-- 3. First-page data embedded in the page, saving a round-trip --}}
    @linkerRefSeed('budget', $budgetSeed ?? null)
</div>

Component ​

php
class BudgetLinker extends LinkerComponent
{
    public static string $alias = 'budget';

    /** Shared by the seed and dom.repeat, so both always have the same shape */
    public static function page(int $userId, int $page = 1): array
    {
        return Budget::query()
            ->where('user_id', $userId)
            ->orderByDesc('year')
            ->paginate(20, ['id', 'year', 'month', 'amount'], 'page', $page)
            ->toArray();
    }

    #[Computable]
    #[Validate(['page' => 'nullable|integer|min:1'])]
    public function show(array $args): LinkerResponse
    {
        return $this->ok()->call('dom.repeat', [
            'ref' => 'budget',
            'items' => self::page(auth()->id(), $args['page'] ?? 1),
            'mode' => 'replace',
        ]);
    }

    #[Computable]
    #[Validate(['id' => 'required|integer'])]
    #[Authorize('delete', Budget::class, arg: 'id')]
    public function delete(array $args): LinkerResponse
    {
        Budget::query()->findOrFail($args['id'])->delete();

        return $this->show([]);
    }
}

Controller ​

php
public function index(): View
{
    return view('pages.budget.index', [
        'budgetSeed' => BudgetLinker::page(auth()->id()),
    ]);
}

dom.repeat arguments ​

ArgumentTypeNotes
itemsarrayA plain array, or paginator shape (data + total + current_page…)
refstring?Template name, matching data-linker-ref-dom
modestring?replace (default) / append / prepend
  • replace removes everything at that level except the template and the empty state, including rows rendered by the server on first load.
  • append fits "load more" and infinite scroll.
php
// Load more
return $this->ok()->call('dom.repeat', ['ref' => 'budget', 'items' => $next, 'mode' => 'append']);

Markers ​

MarkerEffect
data-linker-ref-dom="name"The template. Copies lose this attribute, the hidden attribute and the hidden class, and gain data-linker-ref-clone
data-linker-ref-empty="name"Shown when there are 0 rows
data-linker-ref-meta="name:field"Filled with a top-level field of items (total, current_page, last_page…)
data-linker-ref-allow="data-x aria-y"Extra plain-text attributes that may be filled
%field%, %a.b%Values from the row (nesting allowed)
%lang:group.key%A translation from window.trans; :field is replaced with the row's value
@linkerRefSeed('name', $data)First-page data (a JSON script, applied once)

Where placeholders may go ​

The whole process bypasses the HTML parser. Positions are allow-listed:

PositionCheck
Text of td th span div p a button label li option h1–h6…Treated as text; emptied inside script style textarea svg
title alt placeholder value label datetime aria-label…Plain text
colspan rowspan min max step aria-value*Removed if not a number
classEach word may only contain letters, digits and - _ : / . [ ]
href (<a> <area>), src (<img> <source> <audio> <video> <track>)Only http(s), mailto, tel and relative URLs
data-linker-argsValues are JSON-encoded; removed if the result isn't valid JSON

Any other attribute (id, name, style, on*, data-linker-call…) containing a placeholder is removed entirely, with a console warning.

dom.repeat or render.fragment? ​

dom.repeatrender.fragment
SendsJSON data onlyA whole block of HTML
Row structureIdentical rowsRows can differ, with conditional blocks
Blade logic (@can, @if)Not inside rowsYes
Without JSOnly the empty state showsFirst load works normally
Good forBig tables, pagination, load more, live updatesComplex cards, detail views

Common mistakes ​

  • Template not inside @linker → repeat() only looks for templates inside the mount point.
  • The empty state flashes → hide it on the server based on total.
  • Buttons in copied rows don't respond → just write data-linker-call on the template; after insertion cg:rendered binds it. Don't put it in data-linker-ref-allow.
  • Using %id% as an element id → id isn't allowed and gets removed. Use a data-* attribute and add it to data-linker-ref-allow.