Class that handles header and footer includes looks like a mess I tried making a class that handles my header and footer of my site. It looks like a mess, because I like to preserve the indentations as is.

But I'm wondering if there maybe is an even cleaner or better way of writing this class?

&lt;?php
class HeadFoot {
    protected $title,
              $scripts;

    public function __construct($title, $scripts) {
        $this-&gt;title = $title;
        $this-&gt;scripts = $scripts;
    }

    public function getHeader() {
        if($this-&gt;title) {
$header = &lt;&lt;&lt; EOD
&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
    &lt;head&gt;
        &lt;meta charset="UTF-8"&gt;
        &lt;title&gt;$this-&gt;title - Domain&lt;/title&gt;
        &lt;link rel="shortcut icon" href="/favicon.ico"&gt;
        &lt;link rel="stylesheet" href="/stylesheets/init.css"&gt;
        &lt;link rel="stylesheet" href="/stylesheets/layout.css"&gt;

EOD;

if($this-&gt;scripts) {
    foreach($this-&gt;scripts as $script) {
        $header .= str_repeat(' ', 8) . $script . "\n";
    }
}

$header .= &lt;&lt;&lt; EOD
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div id="topbar"&gt;&lt;/div&gt;

        &lt;div id="container"&gt;
            &lt;div id="header"&gt;
                &lt;div class="wrapper"&gt;
                    &lt;h1 id="site-name"&gt;&lt;a href="/"&gt;Domain&lt;/a&gt;&lt;/h1&gt;
                &lt;/div&gt;
            &lt;/div&gt;


EOD;

$header .= Navigation::get();
$header .= str_repeat(' ', 12) . "\n";

            return $header;
        }

        return false;
    }

    public function getFooter($ads = null) {
        if($ads) {
            return
'            &lt;div id="footer"&gt;
                &lt;p&gt;Copyright © 2014 - Domain.net&lt;/p&gt;
                &lt;p&gt;&lt;a href="#" title="Terms of Service"&gt;Terms of Service&lt;/a&gt; / &lt;a href="#" title="Privacy Policy"&gt;Privacy Policy&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;';
        }

        return
'            &lt;div id="advertisement"&gt;
                &lt;script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"&gt;&lt;/script&gt;
                &lt;ins class="adsbygoogle"
                     style="display: inline-block; width: 468px; height: 60px; vertical-align: top;"
                     data-ad-client="ca-pub-8849502800889803"
                     data-ad-slot="2598909127"&gt;&lt;/ins&gt;
                &lt;script&gt;(adsbygoogle = window.adsbygoogle || []).push({});&lt;/script&gt;
            &lt;/div&gt;

            &lt;div id="footer"&gt;
                &lt;p&gt;Copyright © 2014 - Domain.net&lt;/p&gt;
                &lt;p&gt;&lt;a href="#" title="Terms of Service"&gt;Terms of Service&lt;/a&gt; / &lt;a href="#" title="Privacy Policy"&gt;Privacy Policy&lt;/a&gt;&lt;/p&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;';
    }
}
Separation of Concerns

You should implement Separation of Concerns. In your case, don't mix logic with your view. Follow basic MVC, where M (model) is the data source, V (view) is where your HTML is, and C (controller), where all your logic is. In this case, put your HTML in one file, the logic in the other.

Templating

One thing that messes up development is when logic is mixed to the template. It makes the template messy and hard to maintain and visualize. I suggest you take a look at the PHP implementation of Mustache templates. In your controller, simply make a function that loads the template to a variable, feeds it to Mustache, put some data in and done.

Inheritance

One use of inheritance is to hide utility functions. For instance, you can create a View class, where your future views inherit from. 

End Result

You can simply do something as simple as this in the controller!

public function index(){
    $myView = new View('path/to/template');     // Create a view
    $myDataSource = new Model('MODEL_NAME');    // Create a model
    $theData = myDataSource-&gt;getData();         // Grab data
    $theResultHTML = myView-&gt;render($theData);  // Render data to template and print
}