Hello,
There's no direct method to get the list of variables inside a block.
As getTemplateVariables parses the variables in a document in order, an approach would be iterating the variables to check when a block starts and ends to get the variables inside it.
For example:
$docx = new CreateDocxFromTemplate('template.docx');
$variables = $docx->getTemplateVariables();
$variablesBlock = [];
$blockStart = false;
$blockPlacehoderName = '';
foreach ($variables['document'] as $variable) {
// check if the variable is a block placeholder
if (strpos($variable, $docx->getTemplateBlockSymbol()) !== false) {
$blockStart = !$blockStart;
$blockPlacehoderName = $variable;
if (!isset($variablesBlock[$blockPlacehoderName])) {
$variablesBlock[$blockPlacehoderName] = [];
}
}
// if the variable is in a block placeholder and it isn't a block placeholder, add it to the array
if ($blockStart && strpos($variable, $docx->getTemplateBlockSymbol()) === false) {
$variablesBlock[$blockPlacehoderName][] = $variable;
}
}
print_r($variablesBlock);
This sample code generates a new array with the block placeholders as array keys and the variables as values.
Regards.