return $html;
}
+ /**
+ * Returns a string with an image tag
+ *
+ * @param string $src - path to the image
+ * @param string $alt - alt text for the image
+ * @param string | null $title - title for the image
+ * @param string | null $url - url to link the image to
+ * @param string | null $id - id for the image, if $url is not null used for the anchor tag else for the image tag
+ * @param array | null $class - array of classes for the image
+ */
+ function img(string $src, string $alt, string | null $title, string | null $url, string | null $id, array | null $class): string
+ {
+ $html = "";
+
+ if (!is_null($url))
+ $html .= "<a href='$url' id='$id'>";
+
+ $html .= "<img";
+
+ if (!is_null($class)) {
+ $html .= ' class="' . implode(' ', $class) . '"';
+ print_r($class);
+ }
+
+ $html .= " src='$src' alt='$alt'";
+
+ if (!is_null($title))
+ $html .= " title='$title'";
+
+ if (is_null($url) && !is_null($id))
+ $html .= " id='$id'";
+
+ $html .= "/>";
+
+ if (!is_null($url)) {
+ $html .= "</a>";
+ }
+
+ return $html;
+ }
+
/**
* Forms the html for a given array of data
*
$data['images'][$key]['path'] = "../../assets/img/" . $image['id'] . '.' . pathinfo($image['path'], PATHINFO_EXTENSION);
}
+// format image classes
+foreach ($data['images'] as $key => $image) {
+ if (empty($image['class']))
+ $data['images'][$key]['class'] = null;
+ else
+ $data['images'][$key]['class'] = array_map('trim', explode(",", $image['class']));
+}
// create partials:
$partialsPath = BASE_PATH_TEMP . "/partials";
// logo (if any, else probably just a broken image with nothing inside)
$logo = $data['images'][array_search("logo", array_column($data['images'], "id"))];
-$generator->writeToFile($header_path, '<img src="' . $logo['path'] . '" alt="' . $logo['description'] . '" />');
+$generator->writeToFile($header_path, $generator->img($logo['path'], $logo['description'], $logo['title'], $logo['url'], $logo['id'], $logo['class']));
$generator->writeToFile($header_path, '<div></div>');
$generator->writeToFile($header_path, '<ul>');
foreach ($data['menu'] as $item) {
- $generator->writeToFile($header_path, '<li>');
- $generator->writeToFile($header_path, $generator->a('../' . $item['path'], $item['item'], null, null));
- $generator->writeToFile($header_path, '</li>');
+ if (boolval($item['active'])) {
+ $generator->writeToFile($header_path, '<li>');
+ $generator->writeToFile($header_path, $generator->a('../' . $item['path'], $item['item'], null, null));
+ $generator->writeToFile($header_path, '</li>');
+ }
}
$generator->writeToFile($header_path, '</ul>');