slimpundit 1 Posted February 21, 2012 Report 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? Quote Link to post Share on other sites
rob 53 Posted February 21, 2012 Report 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 Quote Link to post Share on other sites
Josee 38 Posted February 21, 2012 Report 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 Quote Link to post Share on other sites
HartleySan 826 Posted February 21, 2012 Report 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 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.