> ## Documentation Index
> Fetch the complete documentation index at: https://docs.alumio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Recursively copy values to children

> Copies a value to nested child properties recursively.

export const FormField = ({property, label, required = false, diType, uiPatterns, children}) => {
  const patterns = Array.isArray(uiPatterns) ? uiPatterns : uiPatterns ? [uiPatterns] : [];
  return <div style={{
    margin: '1.5rem 0'
  }}>
      <div style={{
    display: 'flex',
    alignItems: 'baseline',
    flexWrap: 'wrap',
    gap: '0.5rem',
    marginBottom: '0.25rem'
  }}>
        <strong>{label}</strong>
        <span style={{
    fontSize: '0.7rem',
    fontWeight: 600,
    textTransform: 'uppercase',
    letterSpacing: '0.04em',
    color: required ? '#6241f5' : '#6b7280'
  }}>
          {required ? 'Required' : 'Optional'}
        </span>
      </div>

      <div>{children}</div>

      {diType || patterns.length > 0 ? <p style={{
    fontSize: '0.85rem',
    color: '#6b7280',
    marginBottom: 0
  }}>
          {diType ? <>
              See the <a href={`/references/${diType}`}>{diType}</a> reference.{' '}
            </> : null}
          {patterns.length > 0 ? <>
              Accepts a <a href={`/documentation/placeholders-and-patterns/patterns#${patterns[0]}`}>pattern</a>.
            </> : null}
        </p> : null}
    </div>;
};

Pushes values down from a parent record into each of its child records, all the way through any further levels of nesting. A common use is stamping a parent identifier onto every variant of a product, so each variant carries a reference back to the item it belongs to. You describe which children to reach and which values to copy into them, using placeholders to pull the values from the parent.

This documentation describes: [Schema](/schemas/transformer/recursively-copy-values-to-children)

## Fields

<FormField property="childrenPattern" label="Pattern to children within a parent" required>
  The path that points at the children you want to copy values into. Use dot notation, and use `*` to match every item in a list, such as `variants.*` to reach each variant. The transformer applies your values to every matching child, then looks inside each child for more children matching the same pattern and repeats, so the values flow down through every level.
</FormField>

<FormField property="mergeTemplate" label="Mapping of values from parent to child">
  The values to add to each child, written as a small data structure. Use [placeholders](/references/placeholders) such as `&{identifier}` to pull values from the parent into the child. These values are merged into each child, so the child's existing fields are kept and your new fields are added alongside them.
</FormField>

<FormField property="keepRootContext" label="Keep using the context from the first level">
  An on/off toggle for which record placeholders read from as the copy moves deeper. When on, placeholders always read from the top-level parent, even several levels down. When off (the default), placeholders read from the immediate parent at each level. Leave it off unless you specifically need values from the very top to reach all the way down.
</FormField>

## Sample data

| Field                                       | Value                           |
| ------------------------------------------- | ------------------------------- |
| Pattern to children within a parent         | `variants.*`                    |
| Mapping of values from parent to child      | `{ "parent": "&{identifier}" }` |
| Keep using the context from the first level | On                              |

Input:

```json theme={null}
{
    "product": "T-Shirt",
    "identifier": 1234,
    "variants": [
        { "name": "Red" },
        { "name": "Blue" }
    ]
}
```

Output:

```json theme={null}
{
    "product": "T-Shirt",
    "identifier": 1234,
    "variants": [
        { "name": "Red", "parent": 1234 },
        { "name": "Blue", "parent": 1234 }
    ]
}
```

Each variant now carries a `parent` field pulled from the parent's `identifier`.

```json Configuration theme={null}
{
  "prototype": "recursively-copy-values-to-children",
  "parameters": {
    "childrenPattern": "variants.*",
    "mergeTemplate": { "parent": "&{identifier}" },
    "keepRootContext": true
  }
}
```
