<?php
echo <<<'EOT'
<style>
.item-list {
list-style-type: none;
}
.item-label {
font-weight: bold;
}
</style>
EOT;
echo PHP_EOL;
$product_html_template = file_get_contents('product_html_template.tpl');
$html = '';
$products = [
[
'name' => 'product1',
// other product data
'sizes' => [
['name' => 's', 'link' => '#s1'],
['name' => 'm', 'link' => '#m1']
]
],
[
'name' => 'product2',
// other product data
'sizes' => [
['name' => 's', 'link' => '#s2'],
['name' => 'm', 'link' => '#m2'],
['name' => 'xl', 'link' => '#xl2']
]
]
];
foreach ($products as $product) {
$row = $product_html_template;
foreach ($product as $description_name => $description_value) {
if (!is_array($description_value)) {
if ($description_name == 'name')
$row = str_replace('{{product-name}}', $description_value, $row);
} else {
if ($description_name == 'sizes') {
$sizes = '';
foreach ($description_value as $sub_value) {
$item = '<a href="{{link}}">{{name}}</a>, ';
foreach ($sub_value as $key => $value)
$item = str_replace('{{'.$key.'}}', $value, $item);
$sizes .= $item;
}
$row = str_replace('{{product-size}}', rtrim($sizes, ', '), $row);
}
}
}
$html .= $row.PHP_EOL;
}
echo $html;
?>
<div>
<ul class="item-list">
<li><span class="item-label">Nazwa produktu: </span>{{product-name}}</li>
<li><span class="item-label">Rozmiar: </span>{{product-size}}</li>
</ul>
</div>