slimpundit Posted February 21, 2012 Share Posted February 21, 2012 I made a template and used the include function for the header and footer of all my pages. But what should I do if I want to put some javascript or metatags on a specific page? Link to comment Share on other sites More sharing options...
rob Posted February 21, 2012 Share Posted February 21, 2012 Assign the page specific content to a variable and check to see if the variable is set within the included file: $foo = 'content to include here'; include 'header.php'; In header/footer include file if(isset($foo)) { echo $foo; } Using if() and isset() makes $foo optional, so you can just set content when you need to. 1 Link to comment Share on other sites More sharing options...
Josee Posted February 21, 2012 Share Posted February 21, 2012 Hello, You should be able to use variables. For instance, here is what I do for the "description" meta tag, and for the CSS files: • In the header: <meta name="description" content="<?php print $meta_description ?>" <link rel="stylesheet" type="text/css" href="<?php print BASE_URL.$style ?>" /> • Near the top of each page: $meta_description = "Some description"; $style = 'css/some_file.css'; I hope this helps, 1 Link to comment Share on other sites More sharing options...
HartleySan Posted February 21, 2012 Share Posted February 21, 2012 I guess it depends if the meta tags and JS are page-specific, but I imagine you'd want to write like you normally would. For example, you might have the following PHP: <?php include(header.html); // DB connection and content loading here include(footer.html); ?> And then your footer.html file might look like the following: <script> // JS goes here. </script> </body> </html> Does that make sense? Does this answer your question? 1 Link to comment Share on other sites More sharing options...
Recommended Posts