In an attempt to make my code more encapsulated, and thus easier to read, I've opted to use echo statements to fill in redundant sections across my web application's webpages. For example, all of my pages have the same nav-bar, footer, and header(for the most part). I've implemented a way to "inject" html fragments dynamically, much like jQuery can do. A snippet of my index page looks something like this:
<html lang="en">
<?php
// START Head.
echo "<head>";
// Inject Head here.
echo $page_content['head'];
echo "</head>";
// END Head.
// START Body.
echo "<body>";
// Inject Navbar here.
echo $page_content['navbar'];
// START Div{.container}.
echo "<div class=\"container\">";
// Inject Search Bar here.
echo $page_content['searchbar'];
// Inject Footer content here.
echo $page_content['footer'];
echo "</div>";
// END Div{.container}.
echo "</body>";
// END Body.
?>
The $page_content variable hold all the fragments.
What are the benefits? What are the drawbacks? Are there any concepts I am overlooking here in an attempt to make my code more concise?
Aucun commentaire:
Enregistrer un commentaire