Attempting to create a template for the header element of my PHP site within a functions page. I can get the template to function correctly using heredoc but when I try and include a foreach within this and inster the pdo script within the function I get an error 500 message and cannot work out what is causing the issue.
I need to be able to use a foreach as the data called is part of a site management system which can be changed form the backend.
function template_header($title, $head = '') {
$social_icons = $site->prepare('SELECT * FROM socials');
$social_icons->execute();
$socialicons = $social_icons->fetchAll();
// DO NOT INDENT THE BELOW CODE
echo <<<HEADER
<!DOCTYPE html>
<html lang="en">
<head>
<title>$title - $site_name</title>
$head
</head>
<body>
// HTML HERE
HEADER;
foreach ($socialicons as $sicons) {
echo '<li>
<a href="'.$sicons['social_url'].'" title="'.$sicons['social_name'].'">
<i class="fab fa-'.$sicons['social_fa_icon'].'"></i>
</a>
</li>';
}
echo <<<HEADER
// HTML HERE
HEADER;
}