Never mind my previous reply. If I understand your problem correctly:
$this->LoadModel('Email');
$emailWithoutValues = $this->Email->getContentTemplate($id, $language);
$values = array("first_name"=>"Fredi","password"=>"test","discount_code"=>"DISC20","lala"=>"asdasd");
//Here is a solution if it is an entity
$email = $this->Email->patchEntity($emailWithoutValues, $values);
//Here are two solutions if it is an array
//Here's a step-at-a-time solution
$email = [];
foreach ($emailWithoutValues as $fieldName => $currentValue) {
if (isset($values[$fieldName])) {
$email[$fieldName] = $values[$fieldName];
}
else {
$email[$fieldName] = $emailWithoutValues[$fieldName];
}
}
//Here's the same thing using Cake's Collection and Hash classes
$email = (new Collection($emailWithoutValues))
->map(function($currentValue, $fieldName) use ($values) {
return Hash::get($values, $fieldName) ?? $currentValue;
})->toArray();