Uniform Dynamic Fields in email template

I’m using Uniform to send an email with dynamics fields added via JS. This is working as per the Uniform example (Dynamic Fields - Kirby Uniform) but I’m struggling to get my head around how to access these extra fields in the email template I send. It appears that they just get added to the bottom of the data array, but I need to position them in a specific place in the email so I can’t just loop through the data array, I need to target them specifically. Unlike the Uniform example, I have multiple fields and the user can add as many as they want via the form.

From the Uniform example:


use Uniform\Form;

return function ($kirby)
    $rules = [
       'email' => [
            'rules' => ['required', 'email'],
            'message' => 'Please enter a valid email address',
        'name' => [],

    $shopItems = array_filter($kirby->request()->body()->toArray(), function ($key) {
       return strpos($key, 'shopitem-') === 0;

    foreach ($shopItems as $name => $value) {
       $rules[$name] = [
          'rules' => ['required'],
          'message' => 'The shop item must be present.',

    $form = new Form($rules);

    if ($kirby->request()->is('POST')) {
            'to' => 'me@example.com',
            'from' => 'info@example.com',

    return compact('form', 'shopItems');

How would I grab the shopItems array in the email template?

Haven’t used Uniform in ages, but I think you need a custom email template and spell out the form fields explicitly instead of looping through them, i.e. $data['fieldkey'].

The user can add any number of new fields, so targeting them explicitly won’t work. The best I can come up with on a Friday afternoon is to slice the data array by the number of rules I set in the controller:

    $nested = $data['_data'];
    $packages = array_slice($nested, 79);

Because the dynamic fields are always added to the end of the data array, this seems to work consistently. I just need to remember to change the number (79) if I add new rules.