PHP in HTML5 boilerplate

4k Views Asked by At

I heard about HTML5 Boilerplate by Paul Irish. I watched couple of tutorials about it. I even watched the video by Paul Irish himself about the HTML5 Boilerplate. I just understood that HTML5 boilerplate is a template to create a better, quick and cross browser supported User Interface for your web apps. I just have a little confusion about all the stuff.

Where to put your PHP files when working with boilerplate? I'm just a beginner and I've always worked with PHP working on a localhost embedded with HTML and CSS, so this stuff is kinda new to me. I mean where to put your php code in that template.

I don't know if its a stupid question, just think of a novice asking you stupid things :)

1

There are 1 best solutions below

2
On

You are talking about two separate things - confusing the front-end client-side stuff with the serverside.

If you are used to working with PHP to produce HTML then not much will change. All you need to address is that each page served from the server (i.e. pages generated by the PHP) will need to include the reference to all the CSS and JS required in the HTML5 Boilerplate.

An easy way to achieve this would be to have a php include file containing the header and footer components. For example, in the source for the HTML5 Boilerplate you have a file called index.html, and that contains a line of code:

<!-- Add your site or application content here -->
<p>Hello world! This is HTML5 Boilerplate.</p>

Everything above that include in a file called header.php (for example) and then everything below it include in a file called footer.php

Now every time you serve a PHP page, with whatever content you'd generated serverside, remember to include both these files. This is a standard PHP include technique. All you'd need to ensure was that the paths to each of the JS and CSS sources we handled correctly.

(Alternatively you could use a PHP templating system and have that handle these includes more elegantly. If you have a favourite templating engine use that.)

Edit: Some very basic pseudo code. Example page "index.php"

<?php
include "header.inc.php";
include "html5boilerplate_components.inc.php";
include "my_css.inc.php";
include "my_js.inc.php";

include "homepage_content.inc.php";

include "footer.inc.php";
?>

Then you'd swap out the homepage_content.inc.php for a different file for a different page. (You'd probably have your CSS/JS etc included in the header include if you wanted it to be tidier. Do what works best for your project that allows more most reusable code.)